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());
}
}
}
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());
}
}
}
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));
}
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);
}
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();
}
Aggregations