Search in sources :

Example 86 with MessageProducer

use of javax.jms.MessageProducer in project tomee by apache.

the class EncCmpBean method testJmsConnection.

private void testJmsConnection(final Connection connection) throws JMSException {
    final Session session = connection.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
    final Topic topic = session.createTopic("test");
    final MessageProducer producer = session.createProducer(topic);
    producer.send(session.createMessage());
    producer.close();
    session.close();
    connection.close();
}
Also used : MessageProducer(javax.jms.MessageProducer) Topic(javax.jms.Topic) Session(javax.jms.Session)

Example 87 with MessageProducer

use of javax.jms.MessageProducer in project tomee by apache.

the class AnnotatedFieldInjectionMdbBean method testJmsConnection.

private void testJmsConnection(final javax.jms.Connection connection) throws JMSException {
    final Session session = connection.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
    final Topic topic = session.createTopic("test");
    final MessageProducer producer = session.createProducer(topic);
    producer.send(session.createMessage());
    producer.close();
    session.close();
    connection.close();
}
Also used : MessageProducer(javax.jms.MessageProducer) Topic(javax.jms.Topic) Session(javax.jms.Session)

Example 88 with MessageProducer

use of javax.jms.MessageProducer in project tomee by apache.

the class ChatBean method respond.

private void respond(String text) throws JMSException {
    Connection connection = null;
    Session session = null;
    try {
        connection = connectionFactory.createConnection();
        connection.start();
        // Create a Session
        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        // Create a MessageProducer from the Session to the Topic or Queue
        MessageProducer producer = session.createProducer(answerQueue);
        producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
        // Create a message
        TextMessage message = session.createTextMessage(text);
        // Tell the producer to send the message
        producer.send(message);
    } finally {
        // Clean up
        if (session != null) {
            session.close();
        }
        if (connection != null) {
            connection.close();
        }
    }
}
Also used : Connection(javax.jms.Connection) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session)

Example 89 with MessageProducer

use of javax.jms.MessageProducer in project tomee by apache.

the class ChatBeanTest method test.

public void test() throws Exception {
    EJBContainer.createEJBContainer().getContext().bind("inject", this);
    final Connection connection = connectionFactory.createConnection();
    connection.start();
    final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    final MessageProducer questions = session.createProducer(questionQueue);
    final MessageConsumer answers = session.createConsumer(answerQueue);
    sendText("Hello World!", questions, session);
    assertEquals("Hello, Test Case!", receiveText(answers));
    sendText("How are you?", questions, session);
    assertEquals("I'm doing well.", receiveText(answers));
    sendText("Still spinning?", questions, session);
    assertEquals("Once every day, as usual.", receiveText(answers));
}
Also used : MessageConsumer(javax.jms.MessageConsumer) Connection(javax.jms.Connection) MessageProducer(javax.jms.MessageProducer) Session(javax.jms.Session)

Example 90 with MessageProducer

use of javax.jms.MessageProducer in project tomee by apache.

the class ContextLookupStatelessBean method testJmsConnection.

private void testJmsConnection(final Connection connection) throws JMSException {
    final Session session = connection.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
    final Topic topic = session.createTopic("test");
    final MessageProducer producer = session.createProducer(topic);
    producer.send(session.createMessage());
    producer.close();
    session.close();
    connection.close();
}
Also used : MessageProducer(javax.jms.MessageProducer) Topic(javax.jms.Topic) Session(javax.jms.Session)

Aggregations

MessageProducer (javax.jms.MessageProducer)184 Session (javax.jms.Session)131 TextMessage (javax.jms.TextMessage)74 Message (javax.jms.Message)64 Connection (javax.jms.Connection)60 Test (org.junit.Test)54 MessageConsumer (javax.jms.MessageConsumer)49 JMSException (javax.jms.JMSException)46 Topic (javax.jms.Topic)34 Destination (javax.jms.Destination)31 Queue (javax.jms.Queue)21 ConnectionFactory (javax.jms.ConnectionFactory)12 CountDownLatch (java.util.concurrent.CountDownLatch)10 ObjectMessage (javax.jms.ObjectMessage)10 ModelNode (org.jboss.dmr.ModelNode)10 BytesMessage (javax.jms.BytesMessage)9 QueueSession (javax.jms.QueueSession)9 TemporaryQueue (javax.jms.TemporaryQueue)9 QueueConnection (javax.jms.QueueConnection)7 InitialContext (javax.naming.InitialContext)7