Search in sources :

Example 6 with ByteSequence

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);
}
Also used : ByteSequence(org.apache.activemq.util.ByteSequence)

Example 7 with ByteSequence

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);
}
Also used : ByteSequence(org.apache.activemq.util.ByteSequence)

Example 8 with ByteSequence

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");
}
Also used : ByteSequence(org.apache.activemq.util.ByteSequence)

Example 9 with ByteSequence

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());
}
Also used : ByteSequence(org.apache.activemq.util.ByteSequence)

Example 10 with ByteSequence

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();
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) ActiveMQConnection(org.apache.activemq.ActiveMQConnection) ByteSequence(org.apache.activemq.util.ByteSequence) Session(javax.jms.Session) ActiveMQMessage(org.apache.activemq.command.ActiveMQMessage)

Aggregations

ByteSequence (org.apache.activemq.util.ByteSequence)31 Test (org.junit.Test)13 CountDownLatch (java.util.concurrent.CountDownLatch)6 File (java.io.File)4 ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)4 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)3 ArrayList (java.util.ArrayList)2 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)2 ActiveMQMessage (org.apache.activemq.command.ActiveMQMessage)2 DataStructure (org.apache.activemq.command.DataStructure)2 MessageId (org.apache.activemq.command.MessageId)2 ProducerId (org.apache.activemq.command.ProducerId)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 Calendar (java.util.Calendar)1 Deflater (java.util.zip.Deflater)1 MessageConsumer (javax.jms.MessageConsumer)1 Session (javax.jms.Session)1 ActiveMQConnection (org.apache.activemq.ActiveMQConnection)1 ICoreMessage (org.apache.activemq.artemis.api.core.ICoreMessage)1