Search in sources :

Example 6 with TextMessage

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

the class QpidClient method main.

public static void main(String[] args) throws Exception {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    Properties properties = new Properties();
    properties.load(QpidClient.class.getResourceAsStream("/amqp.properties"));
    AMQConnectionFactory connectionFactory = new AMQConnectionFactory(properties.getProperty("qpidConnectionfactory"));
    Connection connection = connectionFactory.createConnection("guest", "guest");
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    System.out.println("Type your name:");
    String name = reader.readLine();
    TextMessage textMessage = session.createTextMessage(name);
    MessageProducer producer = session.createProducer(session.createQueue("ping"));
    producer.send(textMessage);
    System.out.println("Send message " + name);
    session.close();
    connection.stop();
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) Connection(javax.jms.Connection) AMQConnectionFactory(org.apache.qpid.client.AMQConnectionFactory) MessageProducer(javax.jms.MessageProducer) Properties(java.util.Properties) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session)

Example 7 with TextMessage

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

the class JMSClient method sendToActiveMQ.

private static void sendToActiveMQ(String value) throws Exception {
    ConnectionFactory cf = new ActiveMQConnectionFactory(AMQ_USER, AMQ_PASSWD, AMQ_BROKER_URL);
    Connection conn = cf.createConnection();
    try {
        Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        final MessageProducer producer = session.createProducer(session.createQueue(REQUEST_NAME));
        final MessageConsumer consumer = session.createConsumer(session.createQueue(REPLY_NAME));
        conn.start();
        producer.send(session.createTextMessage(createPayload(value)));
        System.out.println("Message sent. Waiting for reply ...");
        Message message = consumer.receive(3000);
        String reply = ((TextMessage) message).getText();
        System.out.println("REPLY: \n" + reply);
    } finally {
        conn.close();
    }
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) MessageConsumer(javax.jms.MessageConsumer) TextMessage(javax.jms.TextMessage) Message(javax.jms.Message) Connection(javax.jms.Connection) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session)

Example 8 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 {
            System.out.println("Received reply" + "\n" + "----------------------------\n" + reply.getText() + "\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 9 with TextMessage

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

the class JmsBindingTest method testRollbackB.

@Test
public void testRollbackB() throws Exception {
    String command = "rollback.B";
    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(1000));
        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());
        Assert.assertNull(consumer.receive(1000));
        consumer.close();
        consumer = session.createConsumer(_queueOutC);
        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 10 with TextMessage

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

the class JmsBindingTest method testNonTransacted.

@Test
public void testNonTransacted() 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(_queueInNoTx);
        TextMessage message = session.createTextMessage();
        message.setText(command);
        producer.send(message);
        session.close();
        session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageConsumer consumer = session.createConsumer(_queueOutA);
        Assert.assertNull(consumer.receive(1000));
        consumer = session.createConsumer(_queueOutB);
        Assert.assertNull(consumer.receive(1000));
        consumer = session.createConsumer(_queueOutC);
        Assert.assertNull(consumer.receive(1000));
    } 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)

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