Search in sources :

Example 6 with HornetQMixIn

use of org.switchyard.component.test.mixins.hornetq.HornetQMixIn 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 {
    String[] orders = { "BREAD", "PIZZA", "JAM", "POTATO", "MILK", "JAM" };
    if (args.length != 0) {
        orders = args;
    }
    HornetQMixIn hqMixIn = new HornetQMixIn(false).setUser(USER).setPassword(PASSWD);
    hqMixIn.initialize();
    try {
        Session session = hqMixIn.createJMSSession();
        MessageProducer producer = session.createProducer(HornetQMixIn.getJMSQueue(ORDER_QUEUE));
        for (String order : orders) {
            final TextMessage message = session.createTextMessage();
            message.setText(order);
            producer.send(message);
        }
        session.close();
        session = hqMixIn.createJMSSession();
        System.out.println("* * *  SHIPPING ORDERS  * * *");
        MessageConsumer consumer = session.createConsumer(HornetQMixIn.getJMSQueue(SHIPPING_QUEUE));
        Message msg = null;
        while ((msg = consumer.receive(1000)) != null) {
            System.out.println(" - " + hqMixIn.readStringFromJMSMessage(msg));
        }
        System.out.println();
        System.out.println("* * *  PENDING ORDERS (FILLING STOCK)  * * *");
        consumer = session.createConsumer(HornetQMixIn.getJMSQueue(FILLING_STOCK_QUEUE));
        while ((msg = consumer.receive(1000)) != null) {
            System.out.println(" - " + hqMixIn.readStringFromJMSMessage(msg));
        }
        session.close();
        Thread.sleep(2000);
    } finally {
        hqMixIn.uninitialize();
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) TextMessage(javax.jms.TextMessage) Message(javax.jms.Message) MessageProducer(javax.jms.MessageProducer) HornetQMixIn(org.switchyard.component.test.mixins.hornetq.HornetQMixIn) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session)

Example 7 with HornetQMixIn

use of org.switchyard.component.test.mixins.hornetq.HornetQMixIn in project quickstarts by jboss-switchyard.

the class JMSClient method sendToHornetQ.

private static void sendToHornetQ() throws Exception {
    HornetQMixIn hqMixIn = new HornetQMixIn(false).setUser(HQ_USER).setPassword(HQ_PASSWD);
    hqMixIn.initialize();
    Session session = null;
    try {
        session = hqMixIn.createJMSSession();
        final MessageProducer producer = session.createProducer(HornetQMixIn.getJMSQueue(QUEUE_NAME));
        Message message = hqMixIn.createJMSMessageFromResource(MESSAGE_PAYLOAD);
        producer.send(message);
        System.out.println("Message sent. Please see server console output");
    } finally {
        hqMixIn.uninitialize();
    }
}
Also used : Message(javax.jms.Message) MessageProducer(javax.jms.MessageProducer) HornetQMixIn(org.switchyard.component.test.mixins.hornetq.HornetQMixIn) Session(javax.jms.Session)

Aggregations

MessageProducer (javax.jms.MessageProducer)7 Session (javax.jms.Session)7 HornetQMixIn (org.switchyard.component.test.mixins.hornetq.HornetQMixIn)7 TextMessage (javax.jms.TextMessage)5 MessageConsumer (javax.jms.MessageConsumer)4 Message (javax.jms.Message)3