use of javax.jms.Destination in project wildfly by wildfly.
the class TopicMDB method onMessage.
public void onMessage(final Message m) {
try {
TextMessage message = (TextMessage) m;
Destination replyTo = m.getJMSReplyTo();
context.createProducer().setJMSCorrelationID(message.getJMSMessageID()).send(replyTo, message.getText());
} catch (Exception e) {
e.printStackTrace();
}
}
use of javax.jms.Destination in project wildfly by wildfly.
the class ExportImportJournalTestCase method sendMessage.
protected static void sendMessage(Context ctx, String destinationLookup, String text) throws NamingException, JMSException {
ConnectionFactory cf = (ConnectionFactory) ctx.lookup("jms/RemoteConnectionFactory");
assertNotNull(cf);
Destination destination = (Destination) ctx.lookup(destinationLookup);
assertNotNull(destination);
try (JMSContext context = cf.createContext("guest", "guest")) {
TextMessage message = context.createTextMessage(text);
message.setJMSDeliveryMode(DeliveryMode.PERSISTENT);
context.createProducer().send(destination, message);
}
}
use of javax.jms.Destination in project wildfly by wildfly.
the class ExportImportJournalTestCase method receiveMessage.
protected static void receiveMessage(Context ctx, String destinationLookup, boolean expectReceivedMessage, String expectedText) throws NamingException {
ConnectionFactory cf = (ConnectionFactory) ctx.lookup("jms/RemoteConnectionFactory");
assertNotNull(cf);
Destination destination = (Destination) ctx.lookup(destinationLookup);
assertNotNull(destination);
try (JMSContext context = cf.createContext("guest", "guest")) {
JMSConsumer consumer = context.createConsumer(destination);
String text = consumer.receiveBody(String.class, 5000);
if (expectReceivedMessage) {
assertNotNull(text);
assertEquals(expectedText, text);
} else {
assertNull("should not have received any message", text);
}
}
}
use of javax.jms.Destination in project spring-framework by spring-projects.
the class SimpleJmsHeaderMapper method fromHeaders.
@Override
public void fromHeaders(MessageHeaders headers, javax.jms.Message jmsMessage) {
try {
Object jmsCorrelationId = headers.get(JmsHeaders.CORRELATION_ID);
if (jmsCorrelationId instanceof Number) {
jmsCorrelationId = jmsCorrelationId.toString();
}
if (jmsCorrelationId instanceof String) {
try {
jmsMessage.setJMSCorrelationID((String) jmsCorrelationId);
} catch (Exception ex) {
logger.info("Failed to set JMSCorrelationID - skipping", ex);
}
}
Destination jmsReplyTo = getHeaderIfAvailable(headers, JmsHeaders.REPLY_TO, Destination.class);
if (jmsReplyTo != null) {
try {
jmsMessage.setJMSReplyTo(jmsReplyTo);
} catch (Exception ex) {
logger.info("Failed to set JMSReplyTo - skipping", ex);
}
}
String jmsType = getHeaderIfAvailable(headers, JmsHeaders.TYPE, String.class);
if (jmsType != null) {
try {
jmsMessage.setJMSType(jmsType);
} catch (Exception ex) {
logger.info("Failed to set JMSType - skipping", ex);
}
}
Set<String> headerNames = headers.keySet();
for (String headerName : headerNames) {
if (StringUtils.hasText(headerName) && !headerName.startsWith(JmsHeaders.PREFIX)) {
Object value = headers.get(headerName);
if (value != null && SUPPORTED_PROPERTY_TYPES.contains(value.getClass())) {
try {
String propertyName = this.fromHeaderName(headerName);
jmsMessage.setObjectProperty(propertyName, value);
} catch (Exception ex) {
if (headerName.startsWith("JMSX")) {
if (logger.isTraceEnabled()) {
logger.trace("Skipping reserved header '" + headerName + "' since it cannot be set by client");
}
} else if (logger.isWarnEnabled()) {
logger.warn("Failed to map message header '" + headerName + "' to JMS property", ex);
}
}
}
}
}
} catch (Exception ex) {
if (logger.isWarnEnabled()) {
logger.warn("Error occurred while mapping from MessageHeaders to JMS properties", ex);
}
}
}
use of javax.jms.Destination in project spring-framework by spring-projects.
the class AbstractAdaptableMessageListener method getResponseDestination.
private Destination getResponseDestination(Message request, Message response, Session session, Object result) throws JMSException {
if (result instanceof JmsResponse) {
JmsResponse<?> jmsResponse = (JmsResponse) result;
Destination destination = jmsResponse.resolveDestination(getDestinationResolver(), session);
if (destination != null) {
return destination;
}
}
return getResponseDestination(request, response, session);
}
Aggregations