use of org.springframework.jms.core.MessageCreator in project Protocol-Adapter-IEC61850 by OSGP.
the class OsgpRequestMessageSender method send.
public void send(final RequestMessage requestMessage, final String messageType) {
LOGGER.info("Sending request message to OSGP.");
this.iec61850RequestsJmsTemplate.send(new MessageCreator() {
@Override
public Message createMessage(final Session session) throws JMSException {
final ObjectMessage objectMessage = session.createObjectMessage(requestMessage);
objectMessage.setJMSType(messageType);
objectMessage.setStringProperty(Constants.ORGANISATION_IDENTIFICATION, requestMessage.getOrganisationIdentification());
objectMessage.setStringProperty(Constants.DEVICE_IDENTIFICATION, requestMessage.getDeviceIdentification());
return objectMessage;
}
});
}
use of org.springframework.jms.core.MessageCreator in project opennms by OpenNMS.
the class JmsNorthbounder method forwardAlarms.
/* (non-Javadoc)
* @see org.opennms.netmgt.alarmd.api.support.AbstractNorthbounder#forwardAlarms(java.util.List)
*/
@Override
public void forwardAlarms(List<NorthboundAlarm> alarms) throws NorthbounderException {
for (final NorthboundAlarm alarm : alarms) {
final Integer count = alarm.getCount();
LOG.debug("Does destination {} take only first occurances? {} Is new alarm? Has count of {}.", m_jmsDestination.getName(), m_jmsDestination.isFirstOccurrenceOnly(), count);
if (count > 1 && m_jmsDestination.isFirstOccurrenceOnly()) {
LOG.debug("Skipping because not new alarm.");
continue;
}
LOG.debug("Attempting to send a message to {} of type {}", m_jmsDestination.getJmsDestination(), m_jmsDestination.getDestinationType());
try {
m_template.send(m_jmsDestination.getJmsDestination(), new MessageCreator() {
@Override
public Message createMessage(Session session) throws JMSException {
if (m_jmsDestination.isSendAsObjectMessageEnabled()) {
return session.createObjectMessage(alarm);
} else {
return session.createTextMessage(convertAlarmToText(alarm));
}
}
});
LOG.debug("Sent message");
} catch (JmsException e) {
LOG.error("Unable to send alarm to northbound JMS because {}", e.getLocalizedMessage(), e);
}
}
}
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 camel by apache.
the class JmsRequestReplyManualReplyTest method testManualRequestReply.
@Test
public void testManualRequestReply() throws Exception {
context.start();
// send using pure JMS API to set a custom JMSReplyTo
jms.send(new ActiveMQQueue("foo"), new MessageCreator() {
public Message createMessage(Session session) throws JMSException {
TextMessage msg = session.createTextMessage("Hello World");
msg.setJMSReplyTo(new ActiveMQQueue("bar"));
return msg;
}
});
assertTrue(latch.await(5, TimeUnit.SECONDS));
String reply = consumer.receiveBody(tempName, 5000, String.class);
assertEquals("Bye World", reply);
}
Aggregations