use of org.springframework.jms.core.MessageCreator in project camel by apache.
the class JmsJMSReplyToEndpointUsingInOutTest method testCustomJMSReplyToInOut.
@Test
public void testCustomJMSReplyToInOut() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived("My name is Arnio");
// do not use Camel to send and receive to simulate a non Camel client
// use another thread to listen and send the reply
ExecutorService executor = Executors.newFixedThreadPool(1);
executor.submit(new Callable<Object>() {
public Object call() throws Exception {
JmsTemplate jms = new JmsTemplate(amq.getConfiguration().getConnectionFactory());
final TextMessage msg = (TextMessage) jms.receive("nameRequestor");
assertEquals("What's your name", msg.getText());
// there should be a JMSReplyTo so we know where to send the reply
final Destination replyTo = msg.getJMSReplyTo();
// send reply
jms.send(replyTo, new MessageCreator() {
public Message createMessage(Session session) throws JMSException {
TextMessage replyMsg = session.createTextMessage();
replyMsg.setText("My name is Arnio");
replyMsg.setJMSCorrelationID(msg.getJMSCorrelationID());
return replyMsg;
}
});
return null;
}
});
// now get started and send the first message that gets the ball rolling
JmsTemplate jms = new JmsTemplate(amq.getConfiguration().getConnectionFactory());
jms.send("hello", new MessageCreator() {
public Message createMessage(Session session) throws JMSException {
TextMessage msg = session.createTextMessage();
msg.setText("Hello, I'm here");
return msg;
}
});
assertMockEndpointsSatisfied();
executor.shutdownNow();
}
use of org.springframework.jms.core.MessageCreator in project camel by apache.
the class ConsumeJmsBytesMessageTest method testConsumeBytesMessage.
@Test
public void testConsumeBytesMessage() throws Exception {
endpoint.expectedMessageCount(1);
jmsTemplate.setPubSubDomain(false);
jmsTemplate.send("test.bytes", new MessageCreator() {
public Message createMessage(Session session) throws JMSException {
BytesMessage bytesMessage = session.createBytesMessage();
bytesMessage.writeByte((byte) 1);
bytesMessage.writeByte((byte) 2);
bytesMessage.writeByte((byte) 3);
return bytesMessage;
}
});
endpoint.assertIsSatisfied();
assertCorrectBytesReceived();
}
use of org.springframework.jms.core.MessageCreator in project camel by apache.
the class ConsumeJmsMapMessageTest method testConsumeMapMessage.
@Test
public void testConsumeMapMessage() throws Exception {
endpoint.expectedMessageCount(1);
jmsTemplate.setPubSubDomain(false);
jmsTemplate.send("test.map", new MessageCreator() {
public Message createMessage(Session session) throws JMSException {
MapMessage mapMessage = session.createMapMessage();
mapMessage.setString("foo", "abc");
mapMessage.setString("bar", "xyz");
return mapMessage;
}
});
endpoint.assertIsSatisfied();
assertCorrectMapReceived();
}
use of org.springframework.jms.core.MessageCreator in project spring-framework by spring-projects.
the class JmsTransactionManagerTests method testTransactionCommitWithMessageProducer.
@Test
public void testTransactionCommitWithMessageProducer() throws JMSException {
Destination dest = new StubQueue();
ConnectionFactory cf = mock(ConnectionFactory.class);
Connection con = mock(Connection.class);
Session session = mock(Session.class);
MessageProducer producer = mock(MessageProducer.class);
final Message message = mock(Message.class);
given(cf.createConnection()).willReturn(con);
given(con.createSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(session);
given(session.createProducer(dest)).willReturn(producer);
given(session.getTransacted()).willReturn(true);
JmsTransactionManager tm = new JmsTransactionManager(cf);
TransactionStatus ts = tm.getTransaction(new DefaultTransactionDefinition());
JmsTemplate jt = new JmsTemplate(cf);
jt.send(dest, new MessageCreator() {
@Override
public Message createMessage(Session session) throws JMSException {
return message;
}
});
tm.commit(ts);
verify(producer).send(message);
verify(session).commit();
verify(producer).close();
verify(session).close();
verify(con).close();
}
use of org.springframework.jms.core.MessageCreator in project Protocol-Adapter-OSLP by OSGP.
the class OslpLogItemRequestMessageSender method send.
public void send(final OslpLogItemRequestMessage oslpLogItemRequestMessage) {
LOGGER.debug("Sending OslpLogItemRequestMessage");
this.oslpLogItemRequestsJmsTemplate.send(new MessageCreator() {
@Override
public Message createMessage(final Session session) throws JMSException {
final ObjectMessage objectMessage = session.createObjectMessage();
objectMessage.setJMSType(Constants.OSLP_LOG_ITEM_REQUEST);
objectMessage.setStringProperty(Constants.IS_INCOMING, oslpLogItemRequestMessage.isIncoming().toString());
objectMessage.setStringProperty(Constants.DEVICE_UID, oslpLogItemRequestMessage.getDeviceUid());
objectMessage.setStringProperty(Constants.ENCODED_MESSAGE, oslpLogItemRequestMessage.getEncodedMessage());
objectMessage.setStringProperty(Constants.DECODED_MESSAGE, oslpLogItemRequestMessage.getDecodedMessage());
objectMessage.setStringProperty(Constants.DEVICE_IDENTIFICATION, oslpLogItemRequestMessage.getDeviceIdentification());
objectMessage.setStringProperty(Constants.ORGANISATION_IDENTIFICATION, oslpLogItemRequestMessage.getOrganisationIdentification());
objectMessage.setStringProperty(Constants.IS_VALID, oslpLogItemRequestMessage.isValid().toString());
objectMessage.setIntProperty(Constants.PAYLOAD_MESSAGE_SERIALIZED_SIZE, oslpLogItemRequestMessage.getPayloadMessageSerializedSize());
return objectMessage;
}
});
}
Aggregations