use of org.apache.activemq.util.ByteSequence in project activemq-artemis by apache.
the class OpenWireMessageConverter method putMsgDataStructure.
private static void putMsgDataStructure(final DataStructure ds, final WireFormat marshaller, final CoreMessage coreMessage) throws IOException {
final ByteSequence dsBytes = marshaller.marshal(ds);
dsBytes.compact();
coreMessage.putBytesProperty(AMQ_MSG_DATASTRUCTURE, dsBytes.data);
}
use of org.apache.activemq.util.ByteSequence in project activemq-artemis by apache.
the class ActiveMQTextMessageTest method testGetBytes.
public void testGetBytes() throws JMSException, IOException {
ActiveMQTextMessage msg = new ActiveMQTextMessage();
String str = "testText";
msg.setText(str);
msg.beforeMarshall(null);
ByteSequence bytes = msg.getContent();
msg = new ActiveMQTextMessage();
msg.setContent(bytes);
assertEquals(msg.getText(), str);
}
use of org.apache.activemq.util.ByteSequence in project activemq-artemis by apache.
the class MessageSendTest method xtestPerformance.
public void xtestPerformance() throws IOException {
ActiveMQMessage message = new ActiveMQMessage();
message.setProducerId(new ProducerId(new SessionId(new ConnectionId(new ConnectionId("test")), 1), 1));
message.setMessageId(new MessageId(message.getProducerId(), 1));
message.setCommandId((short) 1);
message.setGroupID("group");
message.setGroupSequence(4);
message.setCorrelationId("correlation");
message.setContent(new ByteSequence(new byte[1024], 0, 1024));
message.setTimestamp(System.currentTimeMillis());
message.setDestination(new ActiveMQQueue("TEST"));
int p = 1000000;
long start = System.currentTimeMillis();
for (int i = 0; i < p; i++) {
marshalAndUnmarshall(message, wireFormat);
}
long end = System.currentTimeMillis();
LOG.info("marshaled/unmarshaled: " + p + " msgs at " + (p * 1000f / (end - start)) + " msgs/sec");
}
use of org.apache.activemq.util.ByteSequence in project activemq-artemis by apache.
the class ActiveMQMessageTest method testClearProperties.
public void testClearProperties() throws JMSException {
ActiveMQMessage msg = new ActiveMQMessage();
msg.setStringProperty("test", "test");
msg.setContent(new ByteSequence(new byte[1], 0, 0));
msg.setJMSMessageID(this.jmsMessageID);
msg.clearProperties();
assertNull(msg.getStringProperty("test"));
assertNotNull(msg.getJMSMessageID());
assertNotNull(msg.getContent());
}
use of org.apache.activemq.util.ByteSequence in project activemq-artemis by apache.
the class MQTTOpenwireTest method doTestSendMQTTReceiveJMS.
public void doTestSendMQTTReceiveJMS(String mqttTopic, String jmsDestination) throws Exception {
final MQTTClientProvider provider = getMQTTClientProvider();
initializeConnection(provider);
ActiveMQConnection activeMQConnection = (ActiveMQConnection) cf.createConnection();
try {
// MUST set to true to receive retained messages
activeMQConnection.setUseRetroactiveConsumer(true);
activeMQConnection.start();
Session s = activeMQConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
javax.jms.Topic jmsTopic = s.createTopic(jmsDestination);
MessageConsumer consumer = s.createConsumer(jmsTopic);
// send retained message
final String RETAINED = "RETAINED";
provider.publish(mqttTopic, RETAINED.getBytes(), AT_LEAST_ONCE, true);
// check whether we received retained message on JMS subscribe
ActiveMQMessage message = (ActiveMQMessage) consumer.receive(2000);
assertNotNull("Should get retained message " + mqttTopic + "->" + jmsDestination, message);
ByteSequence bs = message.getContent();
assertEquals(RETAINED, new String(bs.data, bs.offset, bs.length));
for (int i = 0; i < 1; i++) {
String payload = "Test Message: " + i;
provider.publish(mqttTopic, payload.getBytes(), AT_LEAST_ONCE);
message = (ActiveMQMessage) consumer.receive(1000);
assertNotNull("Should get a message " + mqttTopic + "->" + jmsDestination, message);
bs = message.getContent();
assertEquals(payload, new String(bs.data, bs.offset, bs.length));
}
} finally {
activeMQConnection.close();
provider.disconnect();
}
}
Aggregations