Search in sources :

Example 6 with MessageCreator

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;
        }
    });
}
Also used : ObjectMessage(javax.jms.ObjectMessage) Message(javax.jms.Message) RequestMessage(com.alliander.osgp.shared.infra.jms.RequestMessage) ObjectMessage(javax.jms.ObjectMessage) JMSException(javax.jms.JMSException) MessageCreator(org.springframework.jms.core.MessageCreator) Session(javax.jms.Session)

Example 7 with MessageCreator

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);
        }
    }
}
Also used : Message(javax.jms.Message) JmsException(org.springframework.jms.JmsException) NorthboundAlarm(org.opennms.netmgt.alarmd.api.NorthboundAlarm) JMSException(javax.jms.JMSException) MessageCreator(org.springframework.jms.core.MessageCreator) Session(javax.jms.Session)

Example 8 with MessageCreator

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();
}
Also used : BytesMessage(javax.jms.BytesMessage) Message(javax.jms.Message) JMSException(javax.jms.JMSException) BytesMessage(javax.jms.BytesMessage) MessageCreator(org.springframework.jms.core.MessageCreator) Session(javax.jms.Session) Test(org.junit.Test)

Example 9 with MessageCreator

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();
}
Also used : MapMessage(javax.jms.MapMessage) Message(javax.jms.Message) MapMessage(javax.jms.MapMessage) JMSException(javax.jms.JMSException) MessageCreator(org.springframework.jms.core.MessageCreator) Session(javax.jms.Session) Test(org.junit.Test)

Example 10 with MessageCreator

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);
}
Also used : TextMessage(javax.jms.TextMessage) Message(javax.jms.Message) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) JMSException(javax.jms.JMSException) MessageCreator(org.springframework.jms.core.MessageCreator) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Test(org.junit.Test)

Aggregations

Message (javax.jms.Message)12 Session (javax.jms.Session)12 MessageCreator (org.springframework.jms.core.MessageCreator)12 JMSException (javax.jms.JMSException)10 Test (org.junit.Test)7 Destination (javax.jms.Destination)4 ObjectMessage (javax.jms.ObjectMessage)3 TextMessage (javax.jms.TextMessage)3 JmsTemplate (org.springframework.jms.core.JmsTemplate)3 UseMessageIdAsCorrelationIdMessageSentCallback (org.apache.camel.component.jms.reply.UseMessageIdAsCorrelationIdMessageSentCallback)2 RequestMessage (com.alliander.osgp.shared.infra.jms.RequestMessage)1 File (java.io.File)1 ExecutorService (java.util.concurrent.ExecutorService)1 BytesMessage (javax.jms.BytesMessage)1 Connection (javax.jms.Connection)1 ConnectionFactory (javax.jms.ConnectionFactory)1 MapMessage (javax.jms.MapMessage)1 MessageProducer (javax.jms.MessageProducer)1 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)1 RuntimeExchangeException (org.apache.camel.RuntimeExchangeException)1