Search in sources :

Example 11 with Session

use of javax.jms.Session 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)

Example 12 with Session

use of javax.jms.Session 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 13 with Session

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

the class JMSClient method sendToHornetQ.

private static void sendToHornetQ(String value) throws Exception {
    HornetQMixIn hqMixIn = new HornetQMixIn(false).setUser(USER).setPassword(PASSWD);
    hqMixIn.initialize();
    try {
        Session session = hqMixIn.getJMSSession();
        final MessageProducer producer = session.createProducer(HornetQMixIn.getJMSQueue(REQUEST_NAME));
        final MessageConsumer consumer = session.createConsumer(HornetQMixIn.getJMSQueue(REPLY_NAME));
        producer.send(hqMixIn.createJMSMessage(createPayload(value)));
        System.out.println("Message sent. Waiting for reply ...");
        Message message = consumer.receive(3000);
        String reply = hqMixIn.readStringFromJMSMessage(message);
        System.out.println("REPLY: \n" + reply);
    } 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) Session(javax.jms.Session)

Example 14 with Session

use of javax.jms.Session 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 15 with Session

use of javax.jms.Session 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)

Aggregations

Session (javax.jms.Session)231 MessageProducer (javax.jms.MessageProducer)106 Test (org.junit.Test)98 Connection (javax.jms.Connection)88 Message (javax.jms.Message)73 TextMessage (javax.jms.TextMessage)69 JMSException (javax.jms.JMSException)58 MessageConsumer (javax.jms.MessageConsumer)53 Topic (javax.jms.Topic)36 ConnectionFactory (javax.jms.ConnectionFactory)31 Destination (javax.jms.Destination)27 Queue (javax.jms.Queue)26 ObjectMessage (javax.jms.ObjectMessage)24 StubTextMessage (org.springframework.jms.StubTextMessage)20 QueueSession (javax.jms.QueueSession)16 MessagingMessageListenerAdapter (org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter)16 MapMessage (javax.jms.MapMessage)12 MessageCreator (org.springframework.jms.core.MessageCreator)12 BytesMessage (javax.jms.BytesMessage)11 TopicSession (javax.jms.TopicSession)9