- Common ways to obtain TextMessage
private void myMethod () {TextMessage t =
Session session;String text;session.createTextMessage(text)
Session session;session.createTextMessage()
QueueSession senderSession;senderSession.createTextMessage()
- Smart code suggestions by Codota
}
private void handleRequest(Session session, MessageConsumer consumer, MessageProducer producer) throws JMSException { TextMessage msg = (TextMessage) consumer.receive(1000); log.info("Got request: " + msg.getText()); Destination replyDest = msg.getJMSReplyTo(); String correlationId = msg.getJMSCorrelationID(); msg = session.createTextMessage("Pong"); msg.setJMSDestination(replyDest); msg.setJMSCorrelationID(correlationId); producer.send(msg); }
/** * Send a text message to the specified topic * * @param topic * @param message * @throws JMSException */ public void send(String topic, String message, KapuaConnectionContext kcc) throws JMSException { TextMessage textMessage = session.createTextMessage(); Topic jmsTopic = session.createTopic(topic); textMessage.setStringProperty(MessageConstants.PROPERTY_BROKER_ID, kcc.getBrokerId()); textMessage.setStringProperty(MessageConstants.PROPERTY_CLIENT_ID, kcc.getClientId()); textMessage.setLongProperty(MessageConstants.PROPERTY_SCOPE_ID, kcc.getScopeIdAsLong()); textMessage.setStringProperty(MessageConstants.PROPERTY_ORIGINAL_TOPIC, JmsUtil.convertMqttWildCardToJms(topic)); textMessage.setLongProperty(MessageConstants.PROPERTY_ENQUEUED_TIMESTAMP, System.currentTimeMillis()); textMessage.setText(message); textMessage.setJMSDestination(jmsTopic); producer.send(jmsTopic, textMessage); }