List of usage examples for javax.jms ObjectMessage setStringProperty
void setStringProperty(String name, String value) throws JMSException;
From source file:eu.learnpad.simulator.mon.manager.ResponseDispatcher.java
public static void sendResponse(Object object, String enablerName, String answerTopic) { try {//from www .ja va 2s.c o m publicSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); connectionTopic = publishSession.createTopic(answerTopic); tPub = publishSession.createPublisher(connectionTopic); ObjectMessage sendMessage = publishSession.createObjectMessage(); sendMessage.setObject((Serializable) object); sendMessage.setStringProperty("DESTINATION", enablerName); tPub.publish(sendMessage); } catch (JMSException e) { e.printStackTrace(); } }
From source file:eu.learnpad.simulator.mon.manager.ResponseDispatcher.java
public static void sendResponse(ComplexEventResponse response, String enablerName, String answerTopic) { try {//from ww w .j a v a 2s . co m publicSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); connectionTopic = publishSession.createTopic(answerTopic); tPub = publishSession.createPublisher(connectionTopic); ObjectMessage sendMessage = publishSession.createObjectMessage(); sendMessage.setObject((Serializable) response); sendMessage.setStringProperty("DESTINATION", enablerName); tPub.publish(sendMessage); } catch (JMSException e) { e.printStackTrace(); } }
From source file:eu.learnpad.simulator.mon.manager.ResponseDispatcher.java
public static void sendResponse(ComplexEventException exception, String enablerName, String answerTopic) { try {//from w w w . j ava2 s. c o m publicSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); connectionTopic = publishSession.createTopic(answerTopic); tPub = publishSession.createPublisher(connectionTopic); ObjectMessage sendMessage = publishSession.createObjectMessage(); sendMessage.setObject((Serializable) exception); sendMessage.setStringProperty("DESTINATION", enablerName); tPub.publish(sendMessage); } catch (JMSException e) { e.printStackTrace(); } }
From source file:eu.learnpad.simulator.mon.manager.ResponseDispatcher.java
public static void sendScoresEvaluation(HashMap<ScoreType, Float> scores, String destination, String channel, String userid, String simulationSessionID) { try {/*from w w w. jav a 2 s . com*/ publicSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); connectionTopic = publishSession.createTopic(channel); tPub = publishSession.createPublisher(connectionTopic); ObjectMessage sendMessage = publishSession.createObjectMessage(); sendMessage.setObject((Serializable) scores); sendMessage.setStringProperty("DESTINATION", destination); sendMessage.setStringProperty("USERID", userid); sendMessage.setBooleanProperty("ISASCORE", true); sendMessage.setStringProperty("SIMSESSIONID", simulationSessionID); tPub.publish(sendMessage); } catch (JMSException e) { DebugMessages.println(TimeStamp.getCurrentTime(), ResponseDispatcher.class.getSimpleName(), "Exception during sendScoresEvaluation method execution"); } }
From source file:com.cws.esolutions.core.utils.MQUtils.java
/** * Puts an MQ message on a specified queue and returns the associated * correlation ID for retrieval upon request. * * @param connName - The connection name to utilize * @param authData - The authentication data to utilize, if required * @param requestQueue - The request queue name to put the message on * @param targetHost - The target host for the message * @param value - The data to place on the request. MUST be <code>Serialiable</code> * @return <code>String</code> - the JMS correlation ID associated with the message * @throws UtilityException {@link com.cws.esolutions.core.utils.exception.UtilityException} if an error occurs processing */// ww w. j a v a 2s .c om public static final synchronized String sendMqMessage(final String connName, final List<String> authData, final String requestQueue, final String targetHost, final Serializable value) throws UtilityException { final String methodName = MQUtils.CNAME + "sendMqMessage(final String connName, final List<String> authData, final String requestQueue, final String targetHost, final Serializable value) throws UtilityException"; if (DEBUG) { DEBUGGER.debug(methodName); DEBUGGER.debug("Value: {}", connName); DEBUGGER.debug("Value: {}", requestQueue); DEBUGGER.debug("Value: {}", targetHost); DEBUGGER.debug("Value: {}", value); } Connection conn = null; Session session = null; Context envContext = null; InitialContext initCtx = null; MessageProducer producer = null; ConnectionFactory connFactory = null; final String correlationId = RandomStringUtils.randomAlphanumeric(64); if (DEBUG) { DEBUGGER.debug("correlationId: {}", correlationId); } try { try { initCtx = new InitialContext(); envContext = (Context) initCtx.lookup(MQUtils.INIT_CONTEXT); connFactory = (ConnectionFactory) envContext.lookup(connName); } catch (NamingException nx) { // we're probably not in a container connFactory = new ActiveMQConnectionFactory(connName); } if (DEBUG) { DEBUGGER.debug("ConnectionFactory: {}", connFactory); } if (connFactory == null) { throw new UtilityException("Unable to create connection factory for provided name"); } // Create a Connection conn = connFactory.createConnection(authData.get(0), PasswordUtils.decryptText(authData.get(1), authData.get(2), authData.get(3), Integer.parseInt(authData.get(4)), Integer.parseInt(authData.get(5)), authData.get(6), authData.get(7), authData.get(8))); conn.start(); if (DEBUG) { DEBUGGER.debug("Connection: {}", conn); } // Create a Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); if (DEBUG) { DEBUGGER.debug("Session: {}", session); } // Create a MessageProducer from the Session to the Topic or Queue if (envContext != null) { try { producer = session.createProducer((Destination) envContext.lookup(requestQueue)); } catch (NamingException nx) { throw new UtilityException(nx.getMessage(), nx); } } else { Destination destination = session.createTopic(requestQueue); if (DEBUG) { DEBUGGER.debug("Destination: {}", destination); } producer = session.createProducer(destination); } if (producer == null) { throw new JMSException("Failed to create a producer object"); } producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); if (DEBUG) { DEBUGGER.debug("MessageProducer: {}", producer); } ObjectMessage message = session.createObjectMessage(true); message.setJMSCorrelationID(correlationId); message.setStringProperty("targetHost", targetHost); if (DEBUG) { DEBUGGER.debug("correlationId: {}", correlationId); } message.setObject(value); if (DEBUG) { DEBUGGER.debug("ObjectMessage: {}", message); } producer.send(message); } catch (JMSException jx) { throw new UtilityException(jx.getMessage(), jx); } finally { try { // Clean up if (!(session == null)) { session.close(); } if (!(conn == null)) { conn.close(); conn.stop(); } } catch (JMSException jx) { ERROR_RECORDER.error(jx.getMessage(), jx); } } return correlationId; }
From source file:org.apache.servicemix.audit.async.AbstractJmsExchangeListener.java
public void exchangeAccepted(final ExchangeEvent event) { jmsTemplate.send(new MessageCreator() { public Message createMessage(Session session) throws JMSException { createConfigNodeForNamespace(event.getExchange()); ObjectMessage message = session.createObjectMessage(); message.setStringProperty(EVENT, Event.Accepted.name()); message.setObject((Serializable) getSerializer(event.getExchange().getService().getNamespaceURI()) .serialize(event.getExchange())); return message; }//from w ww . j av a 2 s .c o m }); }
From source file:com.alliander.osgp.adapter.protocol.iec61850.infra.messaging.OsgpRequestMessageSender.java
public void send(final RequestMessage requestMessage, final String messageType) { LOGGER.info("Sending request message to OSGP."); this.iec61850RequestsJmsTemplate.send(new MessageCreator() { @Override// w w w .j a v a 2 s . co m 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; } }); }
From source file:com.alliander.osgp.adapter.protocol.oslp.elster.infra.messaging.OsgpRequestMessageSender.java
public void send(final RequestMessage requestMessage, final String messageType) { LOGGER.info("Sending request message to OSGP."); this.osgpRequestsJmsTemplate.send(new MessageCreator() { @Override/*from w w w . j av a 2 s . c o m*/ 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; } }); }
From source file:org.yestech.publish.service.JmsQueuePublishProducer.java
@Override public void send(final IFileArtifact artifact) { final File inputFile = artifact.getFile(); if (inputFile == null) { throw new RuntimeException("file can't be null for file artifact"); }/*from www . j a v a 2 s .c om*/ reset(artifact); jmsTemplate.send(queue, new MessageCreator() { public Message createMessage(Session session) throws JMSException { ObjectMessage message = session.createObjectMessage(); message.setObject(artifact); message.setStringProperty(IPublishConstant.FILE_NAME, inputFile.getName()); message.setStringProperty(IPublishConstant.URL, url); return message; } }); }
From source file:org.osgp.adapter.protocol.dlms.infra.messaging.DlmsLogItemRequestMessageSender.java
public void send(final DlmsLogItemRequestMessage dlmsLogItemRequestMessage) { LOGGER.debug("Sending DlmsLogItemRequestMessage"); this.dlmsLogItemRequestsJmsTemplate.send(new MessageCreator() { @Override/* www . j a v a2 s . com*/ public Message createMessage(final Session session) throws JMSException { final ObjectMessage objectMessage = session.createObjectMessage(); objectMessage.setJMSType(Constants.DLMS_LOG_ITEM_REQUEST); objectMessage.setStringProperty(Constants.IS_INCOMING, dlmsLogItemRequestMessage.isIncoming().toString()); objectMessage.setStringProperty(Constants.ENCODED_MESSAGE, dlmsLogItemRequestMessage.getEncodedMessage()); objectMessage.setStringProperty(Constants.DECODED_MESSAGE, dlmsLogItemRequestMessage.getDecodedMessage()); objectMessage.setStringProperty(Constants.DEVICE_IDENTIFICATION, dlmsLogItemRequestMessage.getDeviceIdentification()); objectMessage.setStringProperty(Constants.IS_VALID, dlmsLogItemRequestMessage.isValid().toString()); objectMessage.setIntProperty(Constants.PAYLOAD_MESSAGE_SERIALIZED_SIZE, dlmsLogItemRequestMessage.getPayloadMessageSerializedSize()); return objectMessage; } }); }