Search in sources :

Example 96 with TextMessage

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

the class TestMsgBusConnection method testConnection.

public void testConnection() throws Exception {
    try {
        driver.run("create database testconndb");
        Message msg = consumer.receive(TIMEOUT);
        assertTrue("Expected TextMessage", msg instanceof TextMessage);
        assertEquals(HCatConstants.HCAT_CREATE_DATABASE_EVENT, msg.getStringProperty(HCatConstants.HCAT_EVENT));
        assertEquals("topic://planetlab.hcat", msg.getJMSDestination().toString());
        HCatEventMessage messageObject = MessagingUtils.getMessage(msg);
        assertEquals("testconndb", messageObject.getDB());
        broker.stop();
        driver.run("drop database testconndb cascade");
        broker.start(true);
        connectClient();
        driver.run("create database testconndb");
        msg = consumer.receive(TIMEOUT);
        assertEquals(HCatConstants.HCAT_CREATE_DATABASE_EVENT, msg.getStringProperty(HCatConstants.HCAT_EVENT));
        assertEquals("topic://planetlab.hcat", msg.getJMSDestination().toString());
        assertEquals("testconndb", messageObject.getDB());
        driver.run("drop database testconndb cascade");
        msg = consumer.receive(TIMEOUT);
        assertEquals(HCatConstants.HCAT_DROP_DATABASE_EVENT, msg.getStringProperty(HCatConstants.HCAT_EVENT));
        assertEquals("topic://planetlab.hcat", msg.getJMSDestination().toString());
        assertEquals("testconndb", messageObject.getDB());
    } catch (NoSuchObjectException nsoe) {
        nsoe.printStackTrace(System.err);
        assert false;
    } catch (AlreadyExistsException aee) {
        aee.printStackTrace(System.err);
        assert false;
    }
}
Also used : TextMessage(javax.jms.TextMessage) HCatEventMessage(org.apache.hive.hcatalog.messaging.HCatEventMessage) Message(javax.jms.Message) AlreadyExistsException(org.apache.hadoop.hive.metastore.api.AlreadyExistsException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) TextMessage(javax.jms.TextMessage) HCatEventMessage(org.apache.hive.hcatalog.messaging.HCatEventMessage)

Example 97 with TextMessage

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

the class JmsBindingTest method testRollbackA.

/**
     * Triggers the 'WorkService' by sending a HornetQ Message to the 'policyQSTransacted' queue.
     */
@Test
public void testRollbackA() throws Exception {
    String command = "rollback.A";
    Connection conn = _connectionFactory.createConnection(HORNETQ_USER, HORNETQ_PASSWORD);
    conn.start();
    try {
        Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageProducer producer = session.createProducer(_queueIn);
        TextMessage message = session.createTextMessage();
        message.setText(command);
        producer.send(message);
        session.close();
        session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageConsumer consumer = session.createConsumer(_queueOutA);
        TextMessage msg = TextMessage.class.cast(consumer.receive(30000));
        Assert.assertEquals(command, msg.getText());
        Assert.assertNull(consumer.receive(1000));
        consumer.close();
        consumer = session.createConsumer(_queueOutB);
        msg = TextMessage.class.cast(consumer.receive(1000));
        Assert.assertEquals(command, msg.getText());
        msg = TextMessage.class.cast(consumer.receive(1000));
        Assert.assertEquals(command, msg.getText());
        msg = TextMessage.class.cast(consumer.receive(1000));
        Assert.assertEquals(command, msg.getText());
        msg = TextMessage.class.cast(consumer.receive(1000));
        Assert.assertEquals(command, msg.getText());
        Assert.assertNull(consumer.receive(1000));
        consumer.close();
        consumer = session.createConsumer(_queueOutC);
        msg = TextMessage.class.cast(consumer.receive(1000));
        Assert.assertEquals(command, msg.getText());
        msg = TextMessage.class.cast(consumer.receive(1000));
        Assert.assertEquals(command, msg.getText());
        msg = TextMessage.class.cast(consumer.receive(1000));
        Assert.assertEquals(command, msg.getText());
        msg = TextMessage.class.cast(consumer.receive(1000));
        Assert.assertEquals(command, msg.getText());
        Assert.assertNull(consumer.receive(1000));
        session.close();
    } finally {
        conn.close();
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) Connection(javax.jms.Connection) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Test(org.junit.Test)

Example 98 with TextMessage

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

the class OrderIntakeClient method main.

/**
     * Main routing for OrderIntakeClient
     * @param args command-line args
     * @throws Exception if something goes wrong.
     */
public static void main(final String[] args) throws Exception {
    HornetQMixIn hqMixIn = new HornetQMixIn(false).setUser(USER).setPassword(PASSWD);
    hqMixIn.initialize();
    try {
        Session session = hqMixIn.getJMSSession();
        MessageProducer producer = session.createProducer(HornetQMixIn.getJMSQueue(ORDER_QUEUE_NAME));
        String orderTxt = readFileContent(args[0]);
        System.out.println("Submitting Order" + "\n" + "----------------------------\n" + orderTxt + "\n----------------------------");
        producer.send(hqMixIn.createJMSMessage(orderTxt));
        MessageConsumer consumer = session.createConsumer(HornetQMixIn.getJMSQueue(ORDERACK_QUEUE_NAME));
        System.out.println("Order submitted ... waiting for reply.");
        TextMessage reply = (TextMessage) consumer.receive(3000);
        if (reply == null) {
            System.out.println("No reply received.");
        } else {
            String str = reply.getText();
            System.out.println("Received reply" + "\n" + "----------------------------\n" + str + "\n----------------------------");
        }
    } finally {
        hqMixIn.uninitialize();
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) MessageProducer(javax.jms.MessageProducer) HornetQMixIn(org.switchyard.component.test.mixins.hornetq.HornetQMixIn) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session)

Example 99 with TextMessage

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

the class ActiveMQClient method main.

/**
     * Only execution point for this application.
     * @param ignored not used.
     * @throws Exception if something goes wrong.
     */
public static void main(final String[] args) throws Exception {
    ActiveMQMixIn mixIn = new ActiveMQMixIn();
    if (args.length == 0) {
        System.err.println("ERROR: Use -Dexec.args to pass a name and language value, e.g. -Dexec.args=\"Skippy english\"");
        return;
    }
    try {
        final Session session = mixIn.getSession();
        final MessageProducer producer = session.createProducer(session.createQueue(QUEUE));
        final TextMessage message = session.createTextMessage();
        String payload = TEMPLATE.replace("@name@", args[0]);
        if (args.length == 2) {
            payload = payload.replace("@lang@", args[1]);
        } else {
            payload = payload.replace("@lang@", "english");
        }
        System.out.println(payload);
        message.setText(payload);
        producer.send(message);
        System.out.println("Sent message [" + message + "]");
        session.close();
    } finally {
        mixIn.uninitialize();
    }
}
Also used : ActiveMQMixIn(org.switchyard.component.test.mixins.activemq.ActiveMQMixIn) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session)

Example 100 with TextMessage

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

the class HornetQClient method main.

/**
     * Only execution point for this application.
     * @param ignored not used.
     * @throws Exception if something goes wrong.
     */
public static void main(final String[] args) throws Exception {
    HornetQMixIn hqMixIn = new HornetQMixIn(false).setUser(USER).setPassword(PASSWD);
    if (args.length == 0) {
        System.err.println("ERROR: Use -Dexec.args to pass a name and language value, e.g. -Dexec.args=\"Skippy english\"");
        return;
    }
    hqMixIn.initialize();
    try {
        final Session session = hqMixIn.createJMSSession();
        final MessageProducer producer = session.createProducer(HornetQMixIn.getJMSQueue(QUEUE));
        final TextMessage message = session.createTextMessage();
        String payload = TEMPLATE.replace("@name@", args[0]);
        if (args.length == 2) {
            payload = payload.replace("@lang@", args[1]);
        } else {
            payload = payload.replace("@lang@", "english");
        }
        System.out.println(payload);
        message.setText(payload);
        producer.send(message);
        System.out.println("Sent message [" + message + "]");
        Thread.sleep(2000);
    } finally {
        hqMixIn.uninitialize();
    }
}
Also used : MessageProducer(javax.jms.MessageProducer) HornetQMixIn(org.switchyard.component.test.mixins.hornetq.HornetQMixIn) 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