Search in sources :

Example 1 with TextMessage

use of javax.jms.TextMessage in project camel by apache.

the class JmsCustomJMSReplyToIssueTest method testCustomJMSReplyTo.

@Test
public void testCustomJMSReplyTo() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("Bye World");
    // start a inOnly route
    template.sendBody("direct:start", "Hello World");
    // now consume using something that is not Camel
    Thread.sleep(1000);
    JmsTemplate jms = new JmsTemplate(amq.getConfiguration().getConnectionFactory());
    TextMessage msg = (TextMessage) jms.receive("in");
    assertEquals("Hello World", msg.getText());
    // there should be a JMSReplyTo so we know where to send the reply
    Destination replyTo = msg.getJMSReplyTo();
    assertEquals("queue://myReplyQueue", replyTo.toString());
    // send reply
    template.sendBody("activemq:" + replyTo.toString(), "Bye World");
    assertMockEndpointsSatisfied();
}
Also used : Destination(javax.jms.Destination) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) JmsTemplate(org.springframework.jms.core.JmsTemplate) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Example 2 with TextMessage

use of javax.jms.TextMessage in project storm by apache.

the class JmsSpoutTest method sendMessage.

public Message sendMessage(ConnectionFactory connectionFactory, Destination destination) throws JMSException {
    Session mySess = connectionFactory.createConnection().createSession(false, Session.CLIENT_ACKNOWLEDGE);
    MessageProducer producer = mySess.createProducer(destination);
    TextMessage msg = mySess.createTextMessage();
    msg.setText("Hello World");
    LOG.info("Sending Message: {}", msg.getText());
    producer.send(msg);
    return msg;
}
Also used : MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session)

Example 3 with TextMessage

use of javax.jms.TextMessage in project hive by apache.

the class TestNotificationListener method onMessage.

@Override
public void onMessage(Message msg) {
    String event;
    try {
        event = msg.getStringProperty(HCatConstants.HCAT_EVENT);
        String format = msg.getStringProperty(HCatConstants.HCAT_MESSAGE_FORMAT);
        String version = msg.getStringProperty(HCatConstants.HCAT_MESSAGE_VERSION);
        String messageBody = ((TextMessage) msg).getText();
        actualMessages.add(event);
        MessageDeserializer deserializer = MessageFactory.getDeserializer(format, version);
        if (event.equals(HCatConstants.HCAT_CREATE_DATABASE_EVENT)) {
            Assert.assertEquals("topic://" + HCatConstants.HCAT_DEFAULT_TOPIC_PREFIX, msg.getJMSDestination().toString());
            CreateDatabaseMessage message = deserializer.getCreateDatabaseMessage(messageBody);
            Assert.assertEquals("mydb", message.getDB());
            HCatEventMessage message2 = MessagingUtils.getMessage(msg);
            Assert.assertTrue("Unexpected message-type.", message2 instanceof CreateDatabaseMessage);
            Assert.assertEquals("mydb", message2.getDB());
        } else if (event.equals(HCatConstants.HCAT_CREATE_TABLE_EVENT)) {
            Assert.assertEquals("topic://hcat.mydb", msg.getJMSDestination().toString());
            CreateTableMessage message = deserializer.getCreateTableMessage(messageBody);
            Assert.assertEquals("mytbl", message.getTable());
            Assert.assertEquals("mydb", message.getDB());
            HCatEventMessage message2 = MessagingUtils.getMessage(msg);
            Assert.assertTrue("Unexpected message-type.", message2 instanceof CreateTableMessage);
            Assert.assertEquals("mydb", message2.getDB());
            Assert.assertEquals("mytbl", ((CreateTableMessage) message2).getTable());
        } else if (event.equals(HCatConstants.HCAT_ADD_PARTITION_EVENT)) {
            Assert.assertEquals("topic://hcat.mydb.mytbl", msg.getJMSDestination().toString());
            AddPartitionMessage message = deserializer.getAddPartitionMessage(messageBody);
            Assert.assertEquals("mytbl", message.getTable());
            Assert.assertEquals("mydb", message.getDB());
            Assert.assertEquals(1, message.getPartitions().size());
            Assert.assertEquals("2011", message.getPartitions().get(0).get("b"));
            HCatEventMessage message2 = MessagingUtils.getMessage(msg);
            Assert.assertTrue("Unexpected message-type.", message2 instanceof AddPartitionMessage);
            Assert.assertEquals("mydb", message2.getDB());
            Assert.assertEquals("mytbl", ((AddPartitionMessage) message2).getTable());
            Assert.assertEquals(1, ((AddPartitionMessage) message2).getPartitions().size());
            Assert.assertEquals("2011", ((AddPartitionMessage) message2).getPartitions().get(0).get("b"));
        } else if (event.equals(HCatConstants.HCAT_ALTER_PARTITION_EVENT)) {
            Assert.assertEquals("topic://hcat.mydb.mytbl", msg.getJMSDestination().toString());
            // for alter partition events
            AlterPartitionMessage message = deserializer.getAlterPartitionMessage(messageBody);
            Assert.assertEquals("mytbl", message.getTable());
            Assert.assertEquals("mydb", message.getDB());
            Assert.assertEquals(1, message.getKeyValues().size());
            Assert.assertTrue(message.getKeyValues().values().contains("2011"));
            HCatEventMessage message2 = MessagingUtils.getMessage(msg);
            Assert.assertTrue("Unexpected message-type.", message2 instanceof AlterPartitionMessage);
            Assert.assertEquals("mydb", message2.getDB());
            Assert.assertEquals("mytbl", ((AlterPartitionMessage) message2).getTable());
            Assert.assertEquals(1, ((AlterPartitionMessage) message2).getKeyValues().size());
            Assert.assertTrue(((AlterPartitionMessage) message2).getKeyValues().values().contains("2011"));
        } else if (event.equals(HCatConstants.HCAT_DROP_PARTITION_EVENT)) {
            Assert.assertEquals("topic://hcat.mydb.mytbl", msg.getJMSDestination().toString());
            DropPartitionMessage message = deserializer.getDropPartitionMessage(messageBody);
            Assert.assertEquals("mytbl", message.getTable());
            Assert.assertEquals("mydb", message.getDB());
            Assert.assertEquals(1, message.getPartitions().size());
            Assert.assertEquals("2011", message.getPartitions().get(0).get("b"));
            HCatEventMessage message2 = MessagingUtils.getMessage(msg);
            Assert.assertTrue("Unexpected message-type.", message2 instanceof DropPartitionMessage);
            Assert.assertEquals("mydb", message2.getDB());
            Assert.assertEquals("mytbl", ((DropPartitionMessage) message2).getTable());
            Assert.assertEquals(1, ((DropPartitionMessage) message2).getPartitions().size());
            Assert.assertEquals("2011", ((DropPartitionMessage) message2).getPartitions().get(0).get("b"));
        } else if (event.equals(HCatConstants.HCAT_DROP_TABLE_EVENT)) {
            Assert.assertEquals("topic://hcat.mydb", msg.getJMSDestination().toString());
            DropTableMessage message = deserializer.getDropTableMessage(messageBody);
            Assert.assertEquals("mytbl", message.getTable());
            Assert.assertEquals("mydb", message.getDB());
            HCatEventMessage message2 = MessagingUtils.getMessage(msg);
            Assert.assertTrue("Unexpected message-type.", message2 instanceof DropTableMessage);
            Assert.assertEquals("mydb", message2.getDB());
            Assert.assertEquals("mytbl", ((DropTableMessage) message2).getTable());
        } else if (event.equals(HCatConstants.HCAT_DROP_DATABASE_EVENT)) {
            Assert.assertEquals("topic://" + HCatConstants.HCAT_DEFAULT_TOPIC_PREFIX, msg.getJMSDestination().toString());
            DropDatabaseMessage message = deserializer.getDropDatabaseMessage(messageBody);
            Assert.assertEquals("mydb", message.getDB());
            HCatEventMessage message2 = MessagingUtils.getMessage(msg);
            Assert.assertTrue("Unexpected message-type.", message2 instanceof DropDatabaseMessage);
            Assert.assertEquals("mydb", message2.getDB());
        } else if (event.equals(HCatConstants.HCAT_ALTER_TABLE_EVENT)) {
            Assert.assertEquals("topic://hcat.mydb", msg.getJMSDestination().toString());
            AlterTableMessage message = deserializer.getAlterTableMessage(messageBody);
            Assert.assertEquals("mytbl", message.getTable());
            Assert.assertEquals("mydb", message.getDB());
            HCatEventMessage message2 = MessagingUtils.getMessage(msg);
            Assert.assertTrue("Unexpected message-type.", message2 instanceof AlterTableMessage);
            Assert.assertEquals("mydb", message2.getDB());
            Assert.assertEquals("mytbl", ((AlterTableMessage) message2).getTable());
        } else if (event.equals(HCatConstants.HCAT_PARTITION_DONE_EVENT)) {
            // TODO: Fill in when PARTITION_DONE_EVENT is supported.
            Assert.assertTrue("Unexpected: HCAT_PARTITION_DONE_EVENT not supported (yet).", false);
        } else {
            Assert.assertTrue("Unexpected event-type: " + event, false);
        }
    } catch (JMSException e) {
        e.printStackTrace(System.err);
        assert false;
    } finally {
        messageReceivedSignal.countDown();
    }
}
Also used : MessageDeserializer(org.apache.hive.hcatalog.messaging.MessageDeserializer) CreateDatabaseMessage(org.apache.hive.hcatalog.messaging.CreateDatabaseMessage) CreateTableMessage(org.apache.hive.hcatalog.messaging.CreateTableMessage) JMSException(javax.jms.JMSException) HCatEventMessage(org.apache.hive.hcatalog.messaging.HCatEventMessage) DropTableMessage(org.apache.hive.hcatalog.messaging.DropTableMessage) DropPartitionMessage(org.apache.hive.hcatalog.messaging.DropPartitionMessage) DropDatabaseMessage(org.apache.hive.hcatalog.messaging.DropDatabaseMessage) AlterTableMessage(org.apache.hive.hcatalog.messaging.AlterTableMessage) AddPartitionMessage(org.apache.hive.hcatalog.messaging.AddPartitionMessage) TextMessage(javax.jms.TextMessage) AlterPartitionMessage(org.apache.hive.hcatalog.messaging.AlterPartitionMessage)

Example 4 with TextMessage

use of javax.jms.TextMessage in project javaee7-samples by javaee-samples.

the class MessageReceiverAsync method onMessage.

@Override
public void onMessage(Message message) {
    try {
        TextMessage tm = (TextMessage) message;
        System.out.println("Message received (async): " + tm.getText());
    } catch (JMSException ex) {
        Logger.getLogger(MessageReceiverAsync.class.getName()).log(Level.SEVERE, null, ex);
    }
}
Also used : JMSException(javax.jms.JMSException) TextMessage(javax.jms.TextMessage)

Example 5 with TextMessage

use of javax.jms.TextMessage in project quickstarts by jboss-switchyard.

the class CamelAmqpBindingTest method sentTextToQueue.

private void sentTextToQueue(String payload) throws Exception {
    Session session = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Destination destination = _mixin.getDestination(AMQPMixIn.DEFAULT_QUEUE_JNDI_LOCATION);
    MessageProducer messageProducer = session.createProducer(destination);
    TextMessage message = session.createTextMessage(payload);
    messageProducer.send(message);
    session.close();
}
Also used : Destination(javax.jms.Destination) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session)

Aggregations

TextMessage (javax.jms.TextMessage)191 Test (org.junit.Test)88 Message (javax.jms.Message)63 Session (javax.jms.Session)62 MessageProducer (javax.jms.MessageProducer)59 JMSException (javax.jms.JMSException)47 MessageConsumer (javax.jms.MessageConsumer)37 Destination (javax.jms.Destination)36 Connection (javax.jms.Connection)31 ObjectMessage (javax.jms.ObjectMessage)22 Queue (javax.jms.Queue)21 QueueSession (javax.jms.QueueSession)18 StubTextMessage (org.springframework.jms.StubTextMessage)18 BytesMessage (javax.jms.BytesMessage)17 ConnectionFactory (javax.jms.ConnectionFactory)11 QueueConnection (javax.jms.QueueConnection)11 CountDownLatch (java.util.concurrent.CountDownLatch)10 JMSContext (javax.jms.JMSContext)9 MapMessage (javax.jms.MapMessage)9 NamingException (javax.naming.NamingException)8