Search in sources :

Example 6 with ObjectMessage

use of javax.jms.ObjectMessage in project Protocol-Adapter-IEC61850 by OSGP.

the class Iec61850LogItemRequestMessageSender method send.

public void send(final Iec61850LogItemRequestMessage iec61850LogItemRequestMessage) {
    LOGGER.debug("Sending Iec61850LogItemRequestMessage");
    this.iec61850LogItemRequestsJmsTemplate.send(new MessageCreator() {

        @Override
        public Message createMessage(final Session session) throws JMSException {
            final ObjectMessage objectMessage = session.createObjectMessage();
            objectMessage.setJMSType(Constants.IEC61850_LOG_ITEM_REQUEST);
            objectMessage.setStringProperty(Constants.IS_INCOMING, iec61850LogItemRequestMessage.isIncoming().toString());
            objectMessage.setStringProperty(Constants.ENCODED_MESSAGE, iec61850LogItemRequestMessage.getEncodedMessage());
            objectMessage.setStringProperty(Constants.DECODED_MESSAGE, iec61850LogItemRequestMessage.getDecodedMessage());
            objectMessage.setStringProperty(Constants.DEVICE_IDENTIFICATION, iec61850LogItemRequestMessage.getDeviceIdentification());
            objectMessage.setStringProperty(Constants.ORGANISATION_IDENTIFICATION, iec61850LogItemRequestMessage.getOrganisationIdentification());
            objectMessage.setStringProperty(Constants.IS_VALID, iec61850LogItemRequestMessage.isValid().toString());
            objectMessage.setIntProperty(Constants.PAYLOAD_MESSAGE_SERIALIZED_SIZE, iec61850LogItemRequestMessage.getPayloadMessageSerializedSize());
            return objectMessage;
        }
    });
}
Also used : ObjectMessage(javax.jms.ObjectMessage) Message(javax.jms.Message) ObjectMessage(javax.jms.ObjectMessage) JMSException(javax.jms.JMSException) MessageCreator(org.springframework.jms.core.MessageCreator) Session(javax.jms.Session)

Example 7 with ObjectMessage

use of javax.jms.ObjectMessage 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 8 with ObjectMessage

use of javax.jms.ObjectMessage in project Protocol-Adapter-IEC61850 by OSGP.

the class OsgpResponseMessageListener method onMessage.

@Override
public void onMessage(final Message message) {
    try {
        LOGGER.info("Received message of type: {}", message.getJMSType());
        final ObjectMessage objectMessage = (ObjectMessage) message;
        final String messageType = objectMessage.getJMSType();
        final String deviceIdentification = objectMessage.getStringProperty(Constants.DEVICE_IDENTIFICATION);
        final ResponseMessage responseMessage = (ResponseMessage) objectMessage.getObject();
        final String result = responseMessage == null ? null : responseMessage.getResult().toString();
        final OsgpException osgpException = responseMessage == null ? null : responseMessage.getOsgpException();
        if (DeviceFunctionDto.valueOf(messageType).equals(DeviceFunctionDto.REGISTER_DEVICE)) {
            this.handleDeviceRegistration(result, deviceIdentification, messageType, osgpException);
        } else {
            throw new UnknownMessageTypeException("Unknown JMSType: " + messageType);
        }
    } catch (final JMSException ex) {
        LOGGER.error("Exception: {} ", ex.getMessage(), ex);
    } catch (final ProtocolAdapterException e) {
        LOGGER.error("ProtocolAdapterException", e);
    } catch (final UnknownMessageTypeException e) {
        LOGGER.error("UnknownMessageTypeException", e);
    }
}
Also used : OsgpException(com.alliander.osgp.shared.exceptionhandling.OsgpException) ObjectMessage(javax.jms.ObjectMessage) JMSException(javax.jms.JMSException) ResponseMessage(com.alliander.osgp.shared.infra.jms.ResponseMessage) ProtocolAdapterException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException) UnknownMessageTypeException(com.alliander.osgp.shared.infra.jms.UnknownMessageTypeException)

Example 9 with ObjectMessage

use of javax.jms.ObjectMessage in project ignite by apache.

the class IgniteJmsStreamerTest method testQueueFromName.

/**
     * @throws Exception If failed.
     */
public void testQueueFromName() throws Exception {
    Destination dest = new ActiveMQQueue(QUEUE_NAME);
    // produce messages into the queue
    produceObjectMessages(dest, false);
    try (IgniteDataStreamer<String, String> dataStreamer = grid().dataStreamer(DEFAULT_CACHE_NAME)) {
        JmsStreamer<ObjectMessage, String, String> jmsStreamer = newJmsStreamer(ObjectMessage.class, dataStreamer);
        jmsStreamer.setDestinationType(Queue.class);
        jmsStreamer.setDestinationName(QUEUE_NAME);
        // subscribe to cache PUT events and return a countdown latch starting at CACHE_ENTRY_COUNT
        CountDownLatch latch = subscribeToPutEvents(CACHE_ENTRY_COUNT);
        jmsStreamer.start();
        // all cache PUT events received in 10 seconds
        latch.await(10, TimeUnit.SECONDS);
        assertAllCacheEntriesLoaded();
        jmsStreamer.stop();
    }
}
Also used : Destination(javax.jms.Destination) ObjectMessage(javax.jms.ObjectMessage) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 10 with ObjectMessage

use of javax.jms.ObjectMessage in project jmeter by apache.

the class SubscriberSampler method extractContent.

private void extractContent(StringBuilder buffer, StringBuilder propBuffer, Message msg, boolean isLast) {
    if (msg != null) {
        try {
            if (msg instanceof TextMessage) {
                buffer.append(((TextMessage) msg).getText());
            } else if (msg instanceof ObjectMessage) {
                ObjectMessage objectMessage = (ObjectMessage) msg;
                if (objectMessage.getObject() != null) {
                    buffer.append(objectMessage.getObject().getClass());
                } else {
                    buffer.append("object is null");
                }
            } else if (msg instanceof BytesMessage) {
                BytesMessage bytesMessage = (BytesMessage) msg;
                buffer.append(bytesMessage.getBodyLength() + " bytes received in BytesMessage");
            } else if (msg instanceof MapMessage) {
                MapMessage mapm = (MapMessage) msg;
                // MapNames are Strings
                @SuppressWarnings("unchecked") Enumeration<String> enumb = mapm.getMapNames();
                while (enumb.hasMoreElements()) {
                    String name = enumb.nextElement();
                    Object obj = mapm.getObject(name);
                    buffer.append(name);
                    buffer.append(",");
                    buffer.append(obj.getClass().getCanonicalName());
                    buffer.append(",");
                    buffer.append(obj);
                    buffer.append("\n");
                }
            }
            Utils.messageProperties(propBuffer, msg);
            if (!isLast && !StringUtils.isEmpty(separator)) {
                propBuffer.append(separator);
                buffer.append(separator);
            }
        } catch (JMSException e) {
            log.error(e.getMessage());
        }
    }
}
Also used : Enumeration(java.util.Enumeration) ObjectMessage(javax.jms.ObjectMessage) MapMessage(javax.jms.MapMessage) BytesMessage(javax.jms.BytesMessage) JMSException(javax.jms.JMSException) TextMessage(javax.jms.TextMessage)

Aggregations

ObjectMessage (javax.jms.ObjectMessage)47 Message (javax.jms.Message)20 Test (org.junit.Test)18 JMSException (javax.jms.JMSException)16 Session (javax.jms.Session)15 TextMessage (javax.jms.TextMessage)11 Serializable (java.io.Serializable)10 Destination (javax.jms.Destination)9 Map (java.util.Map)8 BytesMessage (javax.jms.BytesMessage)8 MapMessage (javax.jms.MapMessage)8 MessageProducer (javax.jms.MessageProducer)7 TreeMap (java.util.TreeMap)6 MessageConsumer (javax.jms.MessageConsumer)6 CountDownLatch (java.util.concurrent.CountDownLatch)5 Event (models.ChatRoom.Event)4 Connection (javax.jms.Connection)3 QueueConnection (javax.jms.QueueConnection)3 QueueSession (javax.jms.QueueSession)3 StreamMessage (javax.jms.StreamMessage)3