Search in sources :

Example 46 with BytesMessage

use of javax.jms.BytesMessage in project activemq-artemis by apache.

the class JMSWebSocketConnectionTest method testSendLargeMessageToClientFromOpenWire.

@Test(timeout = 30000)
public void testSendLargeMessageToClientFromOpenWire() throws Exception {
    JmsConnectionFactory factory = new JmsConnectionFactory(getBrokerQpidJMSConnectionURI());
    JmsConnection connection = (JmsConnection) factory.createConnection();
    sendLargeMessageViaOpenWire();
    try {
        Session session = connection.createSession();
        Queue queue = session.createQueue(getQueueName());
        connection.start();
        MessageConsumer consumer = session.createConsumer(queue);
        Message message = consumer.receive(1000);
        assertNotNull(message);
        assertTrue(message instanceof BytesMessage);
    } finally {
        connection.close();
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) BytesMessage(javax.jms.BytesMessage) Message(javax.jms.Message) JmsConnectionFactory(org.apache.qpid.jms.JmsConnectionFactory) BytesMessage(javax.jms.BytesMessage) JmsConnection(org.apache.qpid.jms.JmsConnection) Queue(javax.jms.Queue) Session(javax.jms.Session) Test(org.junit.Test)

Example 47 with BytesMessage

use of javax.jms.BytesMessage in project activemq-artemis by apache.

the class JMSWebSocketConnectionTest method testSendLargeMessageToClientFromAMQP.

@Ignore("Broker can't accept messages over 65535 right now")
@Test(timeout = 30000)
public void testSendLargeMessageToClientFromAMQP() throws Exception {
    JmsConnectionFactory factory = new JmsConnectionFactory(getBrokerQpidJMSConnectionURI());
    JmsConnection connection = (JmsConnection) factory.createConnection();
    sendLargeMessageViaAMQP();
    try {
        Session session = connection.createSession();
        Queue queue = session.createQueue(getQueueName());
        connection.start();
        MessageConsumer consumer = session.createConsumer(queue);
        Message message = consumer.receive(1000);
        assertNotNull(message);
        assertTrue(message instanceof BytesMessage);
    } finally {
        connection.close();
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) BytesMessage(javax.jms.BytesMessage) Message(javax.jms.Message) JmsConnectionFactory(org.apache.qpid.jms.JmsConnectionFactory) BytesMessage(javax.jms.BytesMessage) JmsConnection(org.apache.qpid.jms.JmsConnection) Queue(javax.jms.Queue) Session(javax.jms.Session) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 48 with BytesMessage

use of javax.jms.BytesMessage in project activemq-artemis by apache.

the class JMSConsumerTest method testSendReceiveBytesMessage.

public void testSendReceiveBytesMessage() throws Exception {
    // Receive a message with the JMS API
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    destination = createDestination(session, destinationType);
    MessageConsumer consumer = session.createConsumer(destination);
    MessageProducer producer = session.createProducer(destination);
    BytesMessage message = session.createBytesMessage();
    message.writeBoolean(true);
    message.writeBoolean(false);
    producer.send(message);
    // Make sure only 1 message was delivered.
    BytesMessage m = (BytesMessage) consumer.receive(1000);
    assertNotNull(m);
    assertTrue(m.readBoolean());
    assertFalse(m.readBoolean());
    assertNull(consumer.receiveNoWait());
}
Also used : MessageConsumer(javax.jms.MessageConsumer) BytesMessage(javax.jms.BytesMessage) MessageProducer(javax.jms.MessageProducer) Session(javax.jms.Session)

Example 49 with BytesMessage

use of javax.jms.BytesMessage in project activemq-artemis by apache.

the class AMQPToOpenwireTest method testObjectMessage.

@Test
public void testObjectMessage() throws Exception {
    Connection connection = null;
    try {
        connection = qpidfactory.createConnection();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Queue queue = session.createQueue(coreQueue.toString());
        MessageProducer producer = session.createProducer(queue);
        ArrayList list = new ArrayList();
        list.add("aString");
        ObjectMessage objectMessage = session.createObjectMessage(list);
        producer.send(objectMessage);
        connection.close();
        connection = factory.createConnection();
        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        queue = session.createQueue(queueName);
        MessageConsumer consumer = session.createConsumer(queue);
        connection.start();
        BytesMessage receive = (BytesMessage) consumer.receive(5000);
        assertNotNull(receive);
        byte[] bytes = new byte[(int) receive.getBodyLength()];
        receive.readBytes(bytes);
        ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bytes));
        list = (ArrayList) ois.readObject();
        assertEquals(list.get(0), "aString");
        connection.close();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (connection != null) {
            connection.close();
        }
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectMessage(javax.jms.ObjectMessage) AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) Connection(javax.jms.Connection) ArrayList(java.util.ArrayList) BytesMessage(javax.jms.BytesMessage) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) Session(javax.jms.Session) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Example 50 with BytesMessage

use of javax.jms.BytesMessage in project activemq-artemis by apache.

the class JMSFailoverListenerTest method testAutomaticFailover.

// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
@Test
public void testAutomaticFailover() throws Exception {
    ActiveMQConnectionFactory jbcf = ActiveMQJMSClient.createConnectionFactoryWithHA(JMSFactoryType.CF, livetc);
    jbcf.setReconnectAttempts(-1);
    jbcf.setBlockOnDurableSend(true);
    jbcf.setBlockOnNonDurableSend(true);
    // Note we set consumer window size to a value so we can verify that consumer credit re-sending
    // works properly on failover
    // The value is small enough that credits will have to be resent several time
    final int numMessages = 10;
    final int bodySize = 1000;
    jbcf.setConsumerWindowSize(numMessages * bodySize / 10);
    ActiveMQConnection conn = JMSUtil.createConnectionAndWaitForTopology(jbcf, 2, 5);
    MyFailoverListener listener = new MyFailoverListener();
    conn.setFailoverListener(listener);
    Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ClientSession coreSession = ((ActiveMQSession) sess).getCoreSession();
    SimpleString jmsQueueName = new SimpleString("myqueue");
    coreSession.createQueue(jmsQueueName, RoutingType.ANYCAST, jmsQueueName, null, true);
    Queue queue = sess.createQueue("myqueue");
    MessageProducer producer = sess.createProducer(queue);
    producer.setDeliveryMode(DeliveryMode.PERSISTENT);
    MessageConsumer consumer = sess.createConsumer(queue);
    byte[] body = RandomUtil.randomBytes(bodySize);
    for (int i = 0; i < numMessages; i++) {
        BytesMessage bm = sess.createBytesMessage();
        bm.writeBytes(body);
        producer.send(bm);
    }
    conn.start();
    JMSFailoverListenerTest.log.info("sent messages and started connection");
    Thread.sleep(2000);
    JMSUtil.crash(liveServer, ((ActiveMQSession) sess).getCoreSession());
    Assert.assertEquals(FailoverEventType.FAILURE_DETECTED, listener.get(0));
    for (int i = 0; i < numMessages; i++) {
        JMSFailoverListenerTest.log.info("got message " + i);
        BytesMessage bm = (BytesMessage) consumer.receive(1000);
        Assert.assertNotNull(bm);
        Assert.assertEquals(body.length, bm.getBodyLength());
    }
    TextMessage tm = (TextMessage) consumer.receiveNoWait();
    Assert.assertNull(tm);
    Assert.assertEquals(FailoverEventType.FAILOVER_COMPLETED, listener.get(1));
    conn.close();
    Assert.assertEquals("Expected 2 FailoverEvents to be triggered", 2, listener.size());
}
Also used : MessageConsumer(javax.jms.MessageConsumer) ActiveMQConnection(org.apache.activemq.artemis.jms.client.ActiveMQConnection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) BytesMessage(javax.jms.BytesMessage) ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) ActiveMQSession(org.apache.activemq.artemis.jms.client.ActiveMQSession) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) ActiveMQSession(org.apache.activemq.artemis.jms.client.ActiveMQSession) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) Test(org.junit.Test)

Aggregations

BytesMessage (javax.jms.BytesMessage)180 Session (javax.jms.Session)79 MessageProducer (javax.jms.MessageProducer)77 MessageConsumer (javax.jms.MessageConsumer)70 Test (org.junit.Test)59 Message (javax.jms.Message)54 TextMessage (javax.jms.TextMessage)47 Connection (javax.jms.Connection)41 Queue (javax.jms.Queue)37 JMSException (javax.jms.JMSException)34 MapMessage (javax.jms.MapMessage)29 ObjectMessage (javax.jms.ObjectMessage)26 StreamMessage (javax.jms.StreamMessage)20 HashMap (java.util.HashMap)18 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)17 Topic (javax.jms.Topic)14 Map (java.util.Map)12 ActiveMQMessage (org.apache.activemq.command.ActiveMQMessage)12 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)10 Destination (javax.jms.Destination)9