Search in sources :

Example 46 with TextMessage

use of javax.jms.TextMessage 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 47 with TextMessage

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

the class MessagingEjb method sendTextMessage.

public void sendTextMessage(final String msg) throws JMSException {
    final TextMessage message = session.createTextMessage(msg);
    this.sendMessage(message, queue, replyQueue);
}
Also used : TextMessage(javax.jms.TextMessage)

Example 48 with TextMessage

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

the class SetMessageDrivenContextInvocationTestCase method testSetMessageDrivenContext.

/**
     * Test that the {@link javax.ejb.MessageDrivenBean#setMessageDrivenContext(javax.ejb.MessageDrivenContext)}
     * was invoked
     *
     * @throws Exception
     */
@Test
public void testSetMessageDrivenContext() throws Exception {
    this.jmsUtil.sendTextMessage("hello world", this.queue, this.replyQueue);
    final Message reply = this.jmsUtil.receiveMessage(replyQueue, 5000);
    Assert.assertNotNull("Reply message was null on reply queue: " + this.replyQueue, reply);
    final TextMessage textMessage = (TextMessage) reply;
    Assert.assertEquals("setMessageDrivenContext method was *not* invoked on MDB", SimpleMDB.SUCCESS_REPLY, textMessage.getText());
}
Also used : TextMessage(javax.jms.TextMessage) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Example 49 with TextMessage

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

the class MDBProxyBean method trigger.

@Override
public void trigger() throws Exception {
    final String goodMorning = "Good morning";
    // send as ObjectMessage
    // this.jmsUtil = (JMSMessagingUtil) getInitialContext().lookup(getEJBJNDIBinding());
    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.assertEquals("Unexpected reply message on reply queue: " + this.replyQueue, CdiIntegrationMDB.REPLY, textMessage.getText());
}
Also used : TextMessage(javax.jms.TextMessage) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage)

Example 50 with TextMessage

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

the class EJB2xMDB method onMessage.

@Override
public void onMessage(Message message) {
    logger.trace("Received message " + message + " in MDB " + this.getClass().getName());
    try {
        if (message.getStringProperty("MessageFormat") != null)
            logger.trace("MessageFormat property = " + message.getStringProperty("MessageFormat"));
        Destination replyTo = message.getJMSReplyTo();
        if (replyTo == null) {
            try {
                logger.trace("mdbContext = " + mdbContext);
                replyTo = (Destination) mdbContext.lookup("jms/replyQueue");
            } catch (Throwable e) {
                logger.warn(e);
            }
        } else {
            logger.trace("Using replyTo from message JMSReplyTo: " + replyTo);
        }
        if (replyTo == null) {
            throw new EJBException("no replyTo Destination");
        }
        final TextMessage tm = (TextMessage) message;
        final String reply = tm.getText() + "processed by: " + hashCode();
        try (JMSContext context = cf.createContext()) {
            context.createProducer().setJMSCorrelationID(message.getJMSMessageID()).send(replyTo, reply);
        }
    } catch (Exception e) {
        logger.error(e);
        throw new EJBException(e);
    }
}
Also used : Destination(javax.jms.Destination) EJBException(javax.ejb.EJBException) TextMessage(javax.jms.TextMessage) JMSContext(javax.jms.JMSContext) EJBException(javax.ejb.EJBException) NamingException(javax.naming.NamingException)

Aggregations

TextMessage (javax.jms.TextMessage)231 Test (org.junit.Test)92 Session (javax.jms.Session)75 MessageProducer (javax.jms.MessageProducer)71 Message (javax.jms.Message)70 JMSException (javax.jms.JMSException)64 Connection (javax.jms.Connection)44 Destination (javax.jms.Destination)44 MessageConsumer (javax.jms.MessageConsumer)44 ObjectMessage (javax.jms.ObjectMessage)25 BytesMessage (javax.jms.BytesMessage)22 Queue (javax.jms.Queue)21 QueueSession (javax.jms.QueueSession)20 StubTextMessage (org.springframework.jms.StubTextMessage)18 ConnectionFactory (javax.jms.ConnectionFactory)13 QueueConnection (javax.jms.QueueConnection)13 CountDownLatch (java.util.concurrent.CountDownLatch)12 MapMessage (javax.jms.MapMessage)11 Topic (javax.jms.Topic)11 JMSContext (javax.jms.JMSContext)9