Search in sources :

Example 61 with Message

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

the class MDB21TestCase method testSimple21MDB.

/**
     * Test a simple 2.1 MDB.
     */
@Test
public void testSimple21MDB() {
    sendTextMessage("Say hello to " + EJB2xMDB.class.getName(), queue, replyQueue);
    final Message reply = receiveMessage(replyQueue, TimeoutUtil.adjust(1000));
    Assert.assertNotNull("Reply message was null on reply queue: " + replyQueue, reply);
}
Also used : Message(javax.jms.Message) Test(org.junit.Test)

Example 62 with Message

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

the class RunAsTestCaseEJBMDB method testSendMessage.

@Test
public void testSendMessage() throws Exception {
    ConnectionFactory cf = null;
    Connection connection = null;
    Session session = null;
    try {
        cf = (ConnectionFactory) initialContext.lookup("jms/RemoteConnectionFactory");
        Queue queue = (Queue) initialContext.lookup(QUEUE_NAME);
        connection = cf.createConnection("guest", "guest");
        //for consumer we need to start connection
        connection.start();
        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageProducer sender = session.createProducer(queue);
        TemporaryQueue replyQueue = session.createTemporaryQueue();
        TextMessage message = session.createTextMessage("hello goodbye");
        message.setJMSReplyTo(replyQueue);
        sender.send(message);
        log.trace("testSendMessage(): Message sent!");
        MessageConsumer consumer = session.createConsumer(replyQueue);
        Message replyMsg = consumer.receive(5000);
        Assert.assertNotNull(replyMsg);
        Assert.assertTrue(replyMsg instanceof TextMessage);
        String actual = ((TextMessage) replyMsg).getText();
        Assert.assertEquals("Howdy Fred! GoodBye user1", actual);
    } finally {
        if (session != null) {
            session.close();
        }
        closeConnection(connection);
    }
}
Also used : ConnectionFactory(javax.jms.ConnectionFactory) MessageConsumer(javax.jms.MessageConsumer) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) Connection(javax.jms.Connection) TemporaryQueue(javax.jms.TemporaryQueue) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) TemporaryQueue(javax.jms.TemporaryQueue) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Test(org.junit.Test)

Example 63 with Message

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

the class RunAsMDBUnitTestCase method testSendMessage.

@Test
public void testSendMessage() throws Exception {
    ConnectionFactory connFactory = lookup("ConnectionFactory", ConnectionFactory.class);
    Connection conn = connFactory.createConnection();
    conn.start();
    Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    TemporaryQueue replyQueue = session.createTemporaryQueue();
    TextMessage msg = session.createTextMessage("Hello world");
    msg.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
    msg.setJMSReplyTo(replyQueue);
    Queue queue = lookup("java:jboss/" + queueName, Queue.class);
    MessageProducer producer = session.createProducer(queue);
    producer.send(msg);
    MessageConsumer consumer = session.createConsumer(replyQueue);
    Message replyMsg = consumer.receive(5000);
    Assert.assertNotNull(replyMsg);
    if (replyMsg instanceof ObjectMessage) {
        Exception e = (Exception) ((ObjectMessage) replyMsg).getObject();
        throw e;
    }
    Assert.assertTrue(replyMsg instanceof TextMessage);
    String actual = ((TextMessage) replyMsg).getText();
    Assert.assertEquals("SUCCESS", actual);
    consumer.close();
    producer.close();
    session.close();
    conn.close();
}
Also used : ConnectionFactory(javax.jms.ConnectionFactory) MessageConsumer(javax.jms.MessageConsumer) ObjectMessage(javax.jms.ObjectMessage) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) ObjectMessage(javax.jms.ObjectMessage) Connection(javax.jms.Connection) TemporaryQueue(javax.jms.TemporaryQueue) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) TemporaryQueue(javax.jms.TemporaryQueue) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Test(org.junit.Test)

Example 64 with Message

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

the class GetCallerPrincipalTestCase method testMDBLifecycle.

/**
     * Run this one in the container so it can lookup the queue
     * @throws Exception
     */
@OperateOnDeployment("test")
@Test
public void testMDBLifecycle() throws Exception {
    deployer.deploy("mdb");
    SecurityClient client = this.login();
    ITestResultsSingleton results = this.getResultsSingleton();
    MessageProducer producer = null;
    MessageConsumer consumer = null;
    QueueConnection conn = null;
    Session session = null;
    try {
        QueueConnectionFactory qcf = (QueueConnectionFactory) new InitialContext().lookup("java:/ConnectionFactory");
        Queue queue = (Queue) new InitialContext().lookup("java:jboss/" + QUEUE_NAME);
        conn = qcf.createQueueConnection("guest", "guest");
        conn.start();
        session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
        TemporaryQueue replyQueue = session.createTemporaryQueue();
        TextMessage msg = session.createTextMessage("Hello world");
        msg.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
        msg.setJMSReplyTo(replyQueue);
        producer = session.createProducer(queue);
        producer.send(msg);
        consumer = session.createConsumer(replyQueue);
        Message replyMsg = consumer.receive(5000);
        Object obj = ((ObjectMessage) replyMsg).getObject();
        log.trace("MDB message get: " + obj);
        Assert.assertEquals(OK + "start", results.getMdb("postconstruct"));
        deployer.undeploy("mdb");
        Assert.assertEquals(OK + "stop", results.getMdb("predestroy"));
    } finally {
        if (consumer != null) {
            consumer.close();
        }
        if (producer != null) {
            producer.close();
        }
        if (session != null) {
            session.close();
        }
        if (conn != null) {
            conn.close();
        }
        client.logout();
    }
}
Also used : SecurityClient(org.jboss.security.client.SecurityClient) MessageConsumer(javax.jms.MessageConsumer) ObjectMessage(javax.jms.ObjectMessage) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) QueueConnectionFactory(javax.jms.QueueConnectionFactory) InitialContext(javax.naming.InitialContext) QueueConnection(javax.jms.QueueConnection) ObjectMessage(javax.jms.ObjectMessage) TemporaryQueue(javax.jms.TemporaryQueue) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) TemporaryQueue(javax.jms.TemporaryQueue) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) QueueSession(javax.jms.QueueSession) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) Test(org.junit.Test)

Example 65 with Message

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

the class JMSQueueManagementTestCase method testChangeMessagePriority.

@Test
public void testChangeMessagePriority() throws Exception {
    MessageProducer producer = session.createProducer(queue);
    Message msgA = session.createTextMessage("A");
    producer.send(msgA);
    producer.send(session.createTextMessage("B"));
    producer.send(session.createTextMessage("C"));
    Set<Integer> priorities = new HashSet<Integer>();
    ModelNode result = execute(getQueueOperation("list-messages"), true);
    Assert.assertEquals(3, result.asInt());
    for (ModelNode node : result.asList()) {
        priorities.add(node.get("JMSPriority").asInt());
    }
    int newPriority = -1;
    for (int i = 0; i < 10; i++) {
        if (!priorities.contains(i)) {
            newPriority = i;
            break;
        }
    }
    ModelNode op = getQueueOperation("change-message-priority");
    op.get("message-id").set(msgA.getJMSMessageID());
    op.get("new-priority").set(newPriority);
    result = execute(op, true);
    Assert.assertTrue(result.isDefined());
    Assert.assertTrue(result.asBoolean());
    result = execute(getQueueOperation("list-messages"), true);
    boolean found = false;
    for (ModelNode node : result.asList()) {
        if (msgA.getJMSMessageID().equals(node.get("JMSMessageID").asString())) {
            Assert.assertEquals(newPriority, node.get("JMSPriority").asInt());
            found = true;
            break;
        }
    }
    Assert.assertTrue(found);
    op = getQueueOperation("change-messages-priority");
    op.get("new-priority").set(newPriority);
    result = execute(op, true);
    Assert.assertTrue(result.isDefined());
    Assert.assertTrue(result.asInt() > 1 && result.asInt() < 4);
    result = execute(getQueueOperation("list-messages"), true);
    for (ModelNode node : result.asList()) {
        Assert.assertEquals(newPriority, node.get("JMSPriority").asInt());
    }
}
Also used : Message(javax.jms.Message) MessageProducer(javax.jms.MessageProducer) ModelNode(org.jboss.dmr.ModelNode) HashSet(java.util.HashSet) Test(org.junit.Test)

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