Search in sources :

Example 21 with MessageProducer

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

the class IgniteJmsStreamerTest method produceObjectMessages.

private void produceObjectMessages(Destination dest, boolean singleMsg) throws JMSException {
    Session ses = connFactory.createConnection().createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageProducer mp = ses.createProducer(dest);
    HashSet<TestTransformers.TestObject> set = new HashSet<>();
    for (String key : TEST_DATA.keySet()) {
        TestTransformers.TestObject to = new TestTransformers.TestObject(key, TEST_DATA.get(key));
        set.add(to);
    }
    int messagesSent;
    if (singleMsg) {
        mp.send(ses.createObjectMessage(set));
        messagesSent = 1;
    } else {
        for (TestTransformers.TestObject to : set) mp.send(ses.createObjectMessage(to));
        messagesSent = set.size();
    }
    if (dest instanceof Queue) {
        try {
            assertEquals(messagesSent, broker.getBroker().getDestinationMap().get(dest).getDestinationStatistics().getMessages().getCount());
        } catch (Exception e) {
            fail(e.toString());
        }
    }
}
Also used : MessageProducer(javax.jms.MessageProducer) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) Queue(javax.jms.Queue) JMSException(javax.jms.JMSException) Session(javax.jms.Session) HashSet(java.util.HashSet)

Example 22 with MessageProducer

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

the class IgniteJmsStreamerTest method produceStringMessages.

private void produceStringMessages(Destination dest, boolean singleMsg) throws JMSException {
    Session ses = connFactory.createConnection().createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageProducer mp = ses.createProducer(dest);
    HashSet<String> set = new HashSet<>();
    for (String key : TEST_DATA.keySet()) set.add(key + "," + TEST_DATA.get(key));
    int messagesSent;
    if (singleMsg) {
        StringBuilder sb = new StringBuilder();
        for (String s : set) sb.append(s).append("|");
        sb.deleteCharAt(sb.length() - 1);
        mp.send(ses.createTextMessage(sb.toString()));
        messagesSent = 1;
    } else {
        for (String s : set) mp.send(ses.createTextMessage(s));
        messagesSent = set.size();
    }
    if (dest instanceof Queue) {
        try {
            assertEquals(messagesSent, broker.getBroker().getDestinationMap().get(dest).getDestinationStatistics().getMessages().getCount());
        } catch (Exception e) {
            fail(e.toString());
        }
    }
}
Also used : MessageProducer(javax.jms.MessageProducer) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) Queue(javax.jms.Queue) JMSException(javax.jms.JMSException) Session(javax.jms.Session) HashSet(java.util.HashSet)

Example 23 with MessageProducer

use of javax.jms.MessageProducer in project hono by eclipse.

the class SendReceiveIT method testMalformedTelemetryMessageGetsRejected.

/**
 * Verifies that the Telemetry endpoint rejects a malformed message.
 *
 * @throws Exception if the test fails.
 */
@Test
public void testMalformedTelemetryMessageGetsRejected() throws Exception {
    givenAReceiver();
    givenASender();
    final CountDownLatch rejected = new CountDownLatch(1);
    // prepare consumer to get some credits for sending
    final MessageConsumer messageConsumer = receiver.getTelemetryConsumer();
    messageConsumer.setMessageListener(message -> {
    });
    final MessageProducer messageProducer = sender.getTelemetryProducer();
    // message lacks device ID and registration assertion
    final Message message = sender.newMessage("body", null, null);
    messageProducer.send(message, new CompletionListener() {

        @Override
        public void onException(final Message message, final Exception exception) {
            LOG.debug("failed to send message as expected: {}", exception.getMessage());
            rejected.countDown();
        }

        @Override
        public void onCompletion(final Message message) {
        // should not happen
        }
    });
    assertTrue(rejected.await(DEFAULT_TEST_TIMEOUT, TimeUnit.MILLISECONDS));
}
Also used : MessageConsumer(javax.jms.MessageConsumer) Message(javax.jms.Message) CompletionListener(javax.jms.CompletionListener) MessageProducer(javax.jms.MessageProducer) CountDownLatch(java.util.concurrent.CountDownLatch) NamingException(javax.naming.NamingException) JMSException(javax.jms.JMSException) Test(org.junit.Test)

Example 24 with MessageProducer

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

the class MessageListenerTest method sendMessage.

private void sendMessage(Connection connection, Destination dest, String content) throws JMSException, InterruptedException {
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageProducer prod = session.createProducer(dest);
    Message message = session.createTextMessage(content);
    prod.send(message);
    prod.close();
    session.close();
    // Give receiver some time to process
    Thread.sleep(500);
}
Also used : Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) MessageProducer(javax.jms.MessageProducer) Session(javax.jms.Session)

Example 25 with MessageProducer

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

the class ApiLog method get.

@GET
@Path("/{txt}")
public Response get(@PathParam("txt") String txt) throws JMSException {
    try (final Connection connection = connectionFactory.createConnection()) {
        connection.start();
        try (final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE)) {
            try (final MessageProducer producer = session.createProducer(vector)) {
                final Message msg = session.createMessage();
                msg.setStringProperty("txt", txt);
                producer.send(msg);
            }
        }
    }
    return Response.ok().build();
}
Also used : Message(javax.jms.Message) Connection(javax.jms.Connection) MessageProducer(javax.jms.MessageProducer) Session(javax.jms.Session) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

MessageProducer (javax.jms.MessageProducer)1512 Session (javax.jms.Session)1302 MessageConsumer (javax.jms.MessageConsumer)987 Connection (javax.jms.Connection)915 TextMessage (javax.jms.TextMessage)888 Test (org.junit.Test)850 Message (javax.jms.Message)646 Queue (javax.jms.Queue)404 JMSException (javax.jms.JMSException)213 Destination (javax.jms.Destination)190 ConnectionFactory (javax.jms.ConnectionFactory)147 BytesMessage (javax.jms.BytesMessage)140 Topic (javax.jms.Topic)140 TopicSession (javax.jms.TopicSession)135 TopicConnection (javax.jms.TopicConnection)115 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)108 ObjectMessage (javax.jms.ObjectMessage)98 CountDownLatch (java.util.concurrent.CountDownLatch)91 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)90 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)88