use of javax.jms.Message 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();
}
}
use of javax.jms.Message in project quickstarts by jboss-switchyard.
the class ActiveMQClient method main.
/**
* Only execution point for this application.
* @param ignored not used.
* @throws Exception if something goes wrong.
*/
public static void main(final String[] args) throws Exception {
String[] orders = { "BREAD", "PIZZA", "JAM", "POTATO", "MILK", "JAM" };
if (args.length != 0) {
orders = args;
}
ActiveMQMixIn mixIn = new ActiveMQMixIn();
try {
Session session = mixIn.getSession();
MessageProducer producer = session.createProducer(session.createQueue(ORDER_QUEUE));
for (String order : orders) {
final TextMessage message = session.createTextMessage();
message.setText(order);
producer.send(message);
}
session.close();
session = mixIn.getSession();
System.out.println("* * * SHIPPING ORDERS * * *");
MessageConsumer consumer = session.createConsumer(session.createQueue(SHIPPING_QUEUE));
Message msg = null;
while ((msg = consumer.receive(1000)) != null) {
if (msg instanceof TextMessage) {
System.out.println(" - " + ((TextMessage) msg).getText());
}
}
System.out.println();
System.out.println("* * * PENDING ORDERS (FILLING STOCK) * * *");
consumer = session.createConsumer(session.createQueue(FILLING_STOCK_QUEUE));
while ((msg = consumer.receive(1000)) != null) {
if (msg instanceof TextMessage) {
System.out.println(" - " + ((TextMessage) msg).getText());
}
}
session.close();
Thread.sleep(2000);
} finally {
mixIn.uninitialize();
}
}
use of javax.jms.Message in project pinpoint by naver.
the class ActiveMQClientITBase method testQueuePull.
@Test
public void testQueuePull() throws Exception {
// Given
final String testQueueName = "TestPullQueue";
final ActiveMQQueue testQueue = new ActiveMQQueue(testQueueName);
final String testMessage = "Hello World for Queue!";
// create producer
ActiveMQSession producerSession = ActiveMQClientITHelper.createSession(getProducerBrokerName(), getProducerBrokerUrl());
MessageProducer producer = producerSession.createProducer(testQueue);
final TextMessage expectedTextMessage = producerSession.createTextMessage(testMessage);
// When
ActiveMQSession consumerSession = ActiveMQClientITHelper.createSession(getConsumerBrokerName(), getConsumerBrokerUrl());
MessageConsumer consumer = consumerSession.createConsumer(testQueue);
// Then
producer.send(expectedTextMessage);
Message message = consumer.receive(1000L);
Assert.assertEquals(testMessage, ((TextMessage) message).getText());
// Wait till all traces are recorded (consumer traces are recorded from another thread)
awaitAndVerifyTraceCount(5, 5000L);
// trace count : 1
verifyProducerSendEvent(testQueue);
// trace count : 4
verifyConsumerPullEvent(testQueue, consumer, expectedTextMessage);
}
use of javax.jms.Message in project spring-framework by spring-projects.
the class JmsInvokerServiceExporter method writeRemoteInvocationResult.
/**
* Send the given RemoteInvocationResult as a JMS message to the originator.
* @param requestMessage current request message
* @param session the JMS Session to use
* @param result the RemoteInvocationResult object
* @throws javax.jms.JMSException if thrown by trying to send the message
*/
protected void writeRemoteInvocationResult(Message requestMessage, Session session, RemoteInvocationResult result) throws JMSException {
Message response = createResponseMessage(requestMessage, session, result);
MessageProducer producer = session.createProducer(requestMessage.getJMSReplyTo());
try {
producer.send(response);
} finally {
JmsUtils.closeMessageProducer(producer);
}
}
use of javax.jms.Message in project spring-framework by spring-projects.
the class MappingJackson2MessageConverter method toMessage.
@Override
public Message toMessage(Object object, Session session) throws JMSException, MessageConversionException {
Message message;
try {
switch(this.targetType) {
case TEXT:
message = mapToTextMessage(object, session, this.objectMapper.writer());
break;
case BYTES:
message = mapToBytesMessage(object, session, this.objectMapper.writer());
break;
default:
message = mapToMessage(object, session, this.objectMapper.writer(), this.targetType);
}
} catch (IOException ex) {
throw new MessageConversionException("Could not map JSON object [" + object + "]", ex);
}
setTypeIdOnMessage(object, message);
return message;
}
Aggregations