Search in sources :

Example 46 with Message

use of javax.jms.Message in project wildfly by wildfly.

the class SendMessagesTestCase method testShutdown.

@Test
public void testShutdown(@ArquillianResource @OperateOnDeployment("singleton") ManagementClient client) throws Exception {
    Connection connection = null;
    try {
        deployer.deploy("mdb");
        ConnectionFactory cf = (ConnectionFactory) ctx.lookup("jms/RemoteConnectionFactory");
        Queue queue = (Queue) ctx.lookup(QUEUE_SEND);
        connection = cf.createConnection("guest", "guest");
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Queue replyQueue = session.createTemporaryQueue();
        MessageProducer sender = session.createProducer(queue);
        MessageConsumer receiver = session.createConsumer(replyQueue);
        connection.start();
        // we do not assume message order since the 1st message will be redelivered
        // after redeployment (as the MDB is interrupted on 1st delivery)
        Set<String> expected = new TreeSet<String>();
        sendMessage(session, sender, replyQueue, "await");
        expected.add("Reply: await");
        // synchronize receiving message
        int awaitInt = awaitSingleton("await before undeploy");
        log.debug("testsuite: first awaitSingleton() returned: " + awaitInt);
        Future<?> undeployed = executor.submit(undeployTask());
        for (int i = 1; i <= 50; i++) {
            String msg = this.getClass().getSimpleName() + " 50loop: " + i;
            // should be bounced by BlockContainerShutdownInterceptor
            sendMessage(session, sender, replyQueue, msg);
            expected.add("Reply: " + msg);
        }
        log.debug("Sent 50 messages during MDB is undeploying");
        // synchronize with transaction timeout
        awaitInt = awaitSingleton("await after undeploy");
        log.debug("testsuite: second awaitSingleton() returned: " + awaitInt);
        undeployed.get(UNDEPLOYED_WAIT_S, SECONDS);
        // deploying via management client, arquillian deployer does not work for some reason
        final ModelNode deployAddr = new ModelNode();
        deployAddr.get(ClientConstants.OP_ADDR).add("deployment", MESSAGE_DRIVEN_BEAN + ".jar");
        deployAddr.get(ClientConstants.OP).set("deploy");
        applyUpdate(deployAddr, managementClient.getControllerClient());
        for (int i = 1; i <= 10; i++) {
            String msg = this.getClass().getSimpleName() + "10loop: " + i;
            sendMessage(session, sender, replyQueue, msg);
            expected.add("Reply: " + msg);
        }
        log.debug("Sent 10 more messages");
        Set<String> received = new TreeSet<String>();
        for (int i = 1; i <= (1 + 50 + 10 + 1); i++) {
            Message msg = receiver.receive(SECONDS.toMillis(RECEIVE_WAIT_S));
            assertNotNull("did not receive message with ordered number " + i + " in " + SECONDS.toMillis(RECEIVE_WAIT_S) + " seconds", msg);
            String text = ((TextMessage) msg).getText();
            received.add(text);
            log.trace(i + ": " + text);
        }
        assertNull(receiver.receiveNoWait());
        assertEquals(expected, received);
    } finally {
        if (connection != null) {
            connection.close();
        }
        deployer.undeploy("mdb");
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) Connection(javax.jms.Connection) ConnectionFactory(javax.jms.ConnectionFactory) TreeSet(java.util.TreeSet) MessageProducer(javax.jms.MessageProducer) ModelNode(org.jboss.dmr.ModelNode) Queue(javax.jms.Queue) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Test(org.junit.Test)

Example 47 with Message

use of javax.jms.Message in project wildfly by wildfly.

the class ObjectMessageTestCase method testObjectMessage.

/**
     * Test that the MDB can process a {@link ObjectMessage} without any classloading issues
     *
     * @throws Exception
     */
@Test
public void testObjectMessage() throws Exception {
    final String goodAfternoon = "Good afternoon!";
    // create the message
    final SimpleMessageInEarLibJar message = new SimpleMessageInEarLibJar(goodAfternoon);
    // send as ObjectMessage
    this.jmsUtil.sendObjectMessage(message, this.objectMessageQueue, this.objectMessageReplyQueue);
    // wait for an reply
    final Message reply = this.jmsUtil.receiveMessage(objectMessageReplyQueue, 5000);
    // test the reply
    Assert.assertNotNull("Reply message was null on reply queue: " + this.objectMessageReplyQueue, reply);
    final SimpleMessageInEarLibJar replyMessage = (SimpleMessageInEarLibJar) ((ObjectMessage) reply).getObject();
    Assert.assertEquals("Unexpected reply message on reply queue: " + this.objectMessageReplyQueue, message, replyMessage);
}
Also used : ObjectMessage(javax.jms.ObjectMessage) Message(javax.jms.Message) MDBAcceptingObjectMessage(org.jboss.as.test.integration.ejb.mdb.objectmessage.MDBAcceptingObjectMessage) SimpleMessageInEarLibJar(org.jboss.as.test.integration.ejb.mdb.objectmessage.SimpleMessageInEarLibJar) Test(org.junit.Test)

Example 48 with Message

use of javax.jms.Message in project wildfly by wildfly.

the class ObjectMessageTestCase method testObjectMessageWithObjectArray.

/**
     * Test that the MDB can process a {@link ObjectMessage} which consists of an array of objects,
     * without any classloading issues
     *
     * @throws Exception
     */
@Test
public void testObjectMessageWithObjectArray() throws Exception {
    final String goodMorning = "Good morning";
    final String goodEvening = "Good evening";
    // create the message
    final SimpleMessageInEarLibJar[] multipleGreetings = new SimpleMessageInEarLibJar[2];
    final SimpleMessageInEarLibJar messageOne = new SimpleMessageInEarLibJar(goodMorning);
    final SimpleMessageInEarLibJar messageTwo = new SimpleMessageInEarLibJar(goodEvening);
    multipleGreetings[0] = messageOne;
    multipleGreetings[1] = messageTwo;
    // send as ObjectMessage
    this.jmsUtil.sendObjectMessage(multipleGreetings, this.objectMessageOfArrayTypeQueue, this.objectMessageOfArrayTypeReplyQueue);
    // wait for an reply
    final Message reply = this.jmsUtil.receiveMessage(objectMessageOfArrayTypeReplyQueue, 5000);
    // test the reply
    Assert.assertNotNull("Reply message was null on reply queue: " + this.objectMessageOfArrayTypeReplyQueue, reply);
    final SimpleMessageInEarLibJar[] replyMessage = (SimpleMessageInEarLibJar[]) ((ObjectMessage) reply).getObject();
    Assert.assertTrue("Unexpected reply message on reply queue: " + this.objectMessageOfArrayTypeReplyQueue, Arrays.equals(replyMessage, multipleGreetings));
}
Also used : ObjectMessage(javax.jms.ObjectMessage) Message(javax.jms.Message) MDBAcceptingObjectMessage(org.jboss.as.test.integration.ejb.mdb.objectmessage.MDBAcceptingObjectMessage) SimpleMessageInEarLibJar(org.jboss.as.test.integration.ejb.mdb.objectmessage.SimpleMessageInEarLibJar) Test(org.junit.Test)

Example 49 with Message

use of javax.jms.Message in project wildfly by wildfly.

the class ConfiguredResourceAdapterNameTestCase method testMDBWithOverriddenResourceAdapterName.

@Test
public void testMDBWithOverriddenResourceAdapterName() throws Exception {
    final String goodMorning = "Hello World";
    // send as TextMessage
    this.jmsUtil.sendTextMessage(goodMorning, this.queue, this.replyQueue);
    // wait for an reply
    final Message reply = this.jmsUtil.receiveMessage(replyQueue, 5000);
    // test the reply
    final TextMessage textMessage = (TextMessage) reply;
    Assert.assertNotNull(textMessage);
    Assert.assertEquals("Unexpected reply message on reply queue: " + this.replyQueue, ConfiguredResourceAdapterNameMDB.REPLY, textMessage.getText());
}
Also used : TextMessage(javax.jms.TextMessage) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Example 50 with Message

use of javax.jms.Message in project wildfly by wildfly.

the class SimpleTimerMDBTestCase method sendMessage.

//the timer is created when the
public void sendMessage() throws Exception {
    final InitialContext ctx = new InitialContext();
    final TopicConnectionFactory factory = (TopicConnectionFactory) ctx.lookup("java:/JmsXA");
    final TopicConnection connection = factory.createTopicConnection();
    connection.start();
    try {
        final TopicSession session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
        final Message message = session.createTextMessage("Test");
        final Destination destination = (Destination) ctx.lookup("topic/myAwesomeTopic");
        final MessageProducer producer = session.createProducer(destination);
        producer.send(message);
        producer.close();
    } finally {
        connection.close();
    }
}
Also used : TopicConnectionFactory(javax.jms.TopicConnectionFactory) Destination(javax.jms.Destination) TopicSession(javax.jms.TopicSession) Message(javax.jms.Message) MessageProducer(javax.jms.MessageProducer) TopicConnection(javax.jms.TopicConnection) InitialContext(javax.naming.InitialContext)

Aggregations

Message (javax.jms.Message)230 TextMessage (javax.jms.TextMessage)103 Test (org.junit.Test)91 Session (javax.jms.Session)86 JMSException (javax.jms.JMSException)77 MessageProducer (javax.jms.MessageProducer)64 ObjectMessage (javax.jms.ObjectMessage)52 MessageConsumer (javax.jms.MessageConsumer)50 Connection (javax.jms.Connection)45 BytesMessage (javax.jms.BytesMessage)37 Destination (javax.jms.Destination)30 MapMessage (javax.jms.MapMessage)26 Queue (javax.jms.Queue)20 ConnectionFactory (javax.jms.ConnectionFactory)18 QueueSession (javax.jms.QueueSession)17 MessageCreator (org.springframework.jms.core.MessageCreator)15 MessageListener (javax.jms.MessageListener)12 Map (java.util.Map)10 StreamMessage (javax.jms.StreamMessage)10 TemporaryQueue (javax.jms.TemporaryQueue)9