use of javax.jms.MessageProducer in project rocketmq-externals by apache.
the class JmsProduceIT method simpleSendTest.
@Test
public void simpleSendTest() throws Exception {
// Send text message
jmsTemplate.execute(destination, new ProducerCallback() {
@Override
public Object doInJms(Session session, MessageProducer producer) throws JMSException {
JmsTextMessage message = (JmsTextMessage) session.createTextMessage("hello world,kafka");
producer.send(destination, message);
Assert.assertNotNull(message.getJMSMessageID());
return message;
}
});
// Send object message
jmsTemplate.execute(destination, new ProducerCallback() {
@Override
public Object doInJms(Session session, MessageProducer producer) throws JMSException {
JmsObjectMessage message = (JmsObjectMessage) session.createObjectMessage(Lists.newArrayList(1, 2, 3));
producer.send(destination, message);
Assert.assertNotNull(message.getJMSMessageID());
return message;
}
});
// Send byte message
jmsTemplate.execute(destination, new ProducerCallback() {
@Override
public Object doInJms(Session session, MessageProducer producer) throws JMSException {
byte[] ts = "Von,Test".getBytes();
JmsBytesMessage message = (JmsBytesMessage) session.createBytesMessage();
message.writeBytes(ts);
producer.send(destination, message);
Assert.assertNotNull(message.getJMSMessageID());
return message;
}
});
}
use of javax.jms.MessageProducer in project hive by apache.
the class NotificationListener method isConnectionHealthy.
/**
* Send a dummy message to probe if the JMS connection is healthy
* @return true if connection is healthy, false otherwise
*/
protected boolean isConnectionHealthy() {
try {
Topic topic = createTopic(getTopicPrefix(getConf()) + "." + HEALTH_CHECK_TOPIC_SUFFIX);
MessageProducer producer = createProducer(topic);
Message msg = session.get().createTextMessage(HEALTH_CHECK_MSG);
producer.send(msg, DeliveryMode.NON_PERSISTENT, 4, 0);
} catch (Exception e) {
return false;
}
return true;
}
use of javax.jms.MessageProducer in project wso2-axis2-transports by wso2.
the class MockEchoEndpoint method setUp.
@Setup
@SuppressWarnings("unused")
private void setUp(JMSTestEnvironment env, JMSRequestResponseChannel channel) throws Exception {
Destination destination = channel.getDestination();
Destination replyDestination = channel.getReplyDestination();
connection = env.getConnectionFactory().createConnection();
connection.setExceptionListener(this);
connection.start();
replyConnection = env.getConnectionFactory().createConnection();
replyConnection.setExceptionListener(this);
final Session replySession = replyConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
final MessageProducer producer = replySession.createProducer(replyDestination);
MessageConsumer consumer = connection.createSession(false, Session.AUTO_ACKNOWLEDGE).createConsumer(destination);
consumer.setMessageListener(new MessageListener() {
public void onMessage(Message message) {
try {
log.info("Message received: ID = " + message.getJMSMessageID());
Message reply;
if (message instanceof BytesMessage) {
reply = replySession.createBytesMessage();
IOUtils.copy(new BytesMessageInputStream((BytesMessage) message), new BytesMessageOutputStream((BytesMessage) reply));
} else if (message instanceof TextMessage) {
reply = replySession.createTextMessage();
((TextMessage) reply).setText(((TextMessage) message).getText());
} else {
// TODO
throw new UnsupportedOperationException("Unsupported message type");
}
reply.setJMSCorrelationID(message.getJMSMessageID());
reply.setStringProperty(BaseConstants.CONTENT_TYPE, message.getStringProperty(BaseConstants.CONTENT_TYPE));
producer.send(reply);
log.info("Message sent: ID = " + reply.getJMSMessageID());
} catch (Throwable ex) {
fireEndpointError(ex);
}
}
});
}
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);
}
Aggregations