use of com.swiftmq.jms.BytesMessageImpl in project swiftmq-ce by iitsoftware.
the class StreamLibDeployer method run.
public void run() {
try {
pullTransaction.commit();
} catch (Exception e) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.streamsSwiftlet.getName(), toString() + "/run, exception committing tx: " + e + ", exiting");
return;
}
try {
BytesMessageImpl msg = (BytesMessageImpl) entry.getMessage();
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.streamsSwiftlet.getName(), toString() + "/run, new message: " + msg);
processChunk(msg);
} catch (Exception e) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.streamsSwiftlet.getName(), toString() + "/run, exception during processing: " + e);
ctx.logSwiftlet.logError(ctx.streamsSwiftlet.getName(), toString() + "/run, exception during processing: " + e);
}
if (closed)
return;
try {
pullTransaction = receiver.createTransaction(false);
pullTransaction.registerMessageProcessor(this);
} catch (Exception e) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.streamsSwiftlet.getName(), toString() + "/run, exception creating new tx: " + e + ", exiting");
return;
}
}
use of com.swiftmq.jms.BytesMessageImpl in project swiftmq-ce by iitsoftware.
the class MQTTSession method visit.
@Override
public void visit(POSendMessage po) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.mqttSwiftlet.getName(), toString() + ", visit, po=" + po + " ...");
try {
BytesMessageImpl jmsMessage = (BytesMessageImpl) po.getJmsMessage();
jmsMessage.reset();
MqttQoS qos = po.getQos();
String topicName = topicNameTranslateReverse(po.getTopicName());
byte[] b = new byte[(int) jmsMessage.getBodyLength()];
jmsMessage.readBytes(b);
ByteBuf byteBuf = new ByteBuf(b);
byteBuf.reset();
int packetId = -1;
if (qos != MqttQoS.AT_MOST_ONCE) {
if (pid == 65535)
pid = 1;
packetId = pid++;
outboundPackets.put(packetId, po);
}
mqttConnection.getOutboundQueue().enqueue(new MqttPublishMessage(new MqttFixedHeader(MqttMessageType.PUBLISH, false, qos, false, 0), new MqttPublishVariableHeader(topicName, packetId), byteBuf));
if (qos == MqttQoS.AT_MOST_ONCE) {
po.getTransaction().commit();
po.getSubscription().restart();
} else
addReplay(packetId, new MqttPublishMessage(new MqttFixedHeader(MqttMessageType.PUBLISH, true, qos, false, 0), new MqttPublishVariableHeader(topicName, packetId), byteBuf));
incMsgsReceived(1);
} catch (QueueTransactionClosedException qtc) {
} catch (Exception e) {
mqttConnection.initiateClose("send message: exception=" + e);
}
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.mqttSwiftlet.getName(), toString() + ", visit, po=" + po + " done");
}
use of com.swiftmq.jms.BytesMessageImpl in project swiftmq-ce by iitsoftware.
the class Producer method send.
public void send(MqttPublishMessage mqttPublishMessage) throws Exception {
MqttFixedHeader fixedHeader = mqttPublishMessage.fixedHeader();
ByteBuf payload = mqttPublishMessage.payload();
BytesMessageImpl bytesMessage = new BytesMessageImpl();
bytesMessage.setJMSDestination(topic);
bytesMessage.setJMSTimestamp(System.currentTimeMillis());
bytesMessage.setJMSMessageID(session.getMqttConnection().nextId());
bytesMessage.setJMSDeliveryMode(DeliveryMode.PERSISTENT);
bytesMessage.setStringProperty(MessageImpl.PROP_USER_ID, session.getMqttConnection().getActiveLogin().getUserName());
bytesMessage.setStringProperty(MessageImpl.PROP_CLIENT_ID, session.getClientId());
if (fixedHeader.isDup())
bytesMessage.setBooleanProperty(MessageImpl.PROP_DOUBT_DUPLICATE, true);
bytesMessage.setIntProperty(PROP_QOS, fixedHeader.qosLevel().value());
payload.reset();
byte[] b = new byte[payload.size()];
payload.readBytes(b);
bytesMessage.writeBytes(b);
transaction = sender.createTransaction();
transaction.putMessage(bytesMessage);
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.mqttSwiftlet.getName(), toString() + ", sent: " + bytesMessage);
}
use of com.swiftmq.jms.BytesMessageImpl in project swiftmq-ce by iitsoftware.
the class ClusterMetricPublisher method createMessage.
private BytesMessageImpl createMessage(Versionable versionable) throws Exception {
BytesMessageImpl msg = new BytesMessageImpl();
versionable.transferToMessage(msg);
msg.setJMSDeliveryMode(javax.jms.DeliveryMode.NON_PERSISTENT);
msg.setJMSDestination(new TopicImpl(QueueManagerImpl.CLUSTER_TOPIC));
msg.setJMSPriority(MessageImpl.MAX_PRIORITY);
if (interval > 0)
msg.setJMSExpiration(System.currentTimeMillis() + interval * 2);
msg.setStringProperty(PROP_SOURCE_ROUTER, SwiftletManager.getInstance().getRouterName());
msg.setReadOnly(false);
return msg;
}
use of com.swiftmq.jms.BytesMessageImpl in project swiftmq-ce by iitsoftware.
the class AMQPNativeOutboundTransformer method transform.
public void transform(Delivery delivery) throws AMQPException, JMSException {
BytesMessageImpl msg = null;
try {
msg = (BytesMessageImpl) delivery.getMessage();
} catch (ClassCastException e) {
throw new JMSException("Unable to transform. JMS message is not a BytesMessage");
}
if (!msg.propertyExists(messageFormat))
throw new JMSException("Message format property not set");
if (!msg.propertyExists(amqpNative) || !msg.getBooleanProperty(amqpNative))
throw new JMSException("Message is not an AMQP native transformation");
byte[] body = msg._getBody();
if (body == null) {
msg.reset();
body = new byte[(int) msg.getBodyLength()];
msg.readBytes(body);
}
delivery.setData(body);
delivery.setMessageFormat(msg.getLongProperty(messageFormat));
}
Aggregations