use of javax.jms.Destination in project storm by apache.
the class JmsSpout method open.
/**
* <code>ISpout</code> implementation.
* <p>
* Connects the JMS spout to the configured JMS destination
* topic/queue.
*/
@SuppressWarnings("rawtypes")
public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) {
if (this.jmsProvider == null) {
throw new IllegalStateException("JMS provider has not been set.");
}
if (this.tupleProducer == null) {
throw new IllegalStateException("JMS Tuple Producer has not been set.");
}
Integer topologyTimeout = (Integer) conf.get("topology.message.timeout.secs");
// TODO fine a way to get the default timeout from storm, so we're not hard-coding to 30 seconds (it could change)
topologyTimeout = topologyTimeout == null ? 30 : topologyTimeout;
if ((topologyTimeout.intValue() * 1000) > this.recoveryPeriod) {
LOG.warn("*** WARNING *** : " + "Recovery period (" + this.recoveryPeriod + " ms.) is less then the configured " + "'topology.message.timeout.secs' of " + topologyTimeout + " secs. This could lead to a message replay flood!");
}
this.queue = new LinkedBlockingQueue<Message>();
this.toCommit = new TreeSet<JmsMessageID>();
this.pendingMessages = new HashMap<JmsMessageID, Message>();
this.collector = collector;
try {
ConnectionFactory cf = this.jmsProvider.connectionFactory();
Destination dest = this.jmsProvider.destination();
this.connection = cf.createConnection();
this.session = connection.createSession(false, this.jmsAcknowledgeMode);
MessageConsumer consumer = session.createConsumer(dest);
consumer.setMessageListener(this);
this.connection.start();
if (this.isDurableSubscription() && this.recoveryPeriod > 0) {
this.recoveryTimer = new Timer();
this.recoveryTimer.scheduleAtFixedRate(new RecoveryTask(), 10, this.recoveryPeriod);
}
} catch (Exception e) {
LOG.warn("Error creating JMS connection.", e);
}
}
use of javax.jms.Destination in project hive by apache.
the class TestMsgBusConnection method connectClient.
private void connectClient() throws JMSException {
ConnectionFactory connFac = new ActiveMQConnectionFactory("tcp://localhost:61616");
Connection conn = connFac.createConnection();
conn.start();
Session session = conn.createSession(true, Session.SESSION_TRANSACTED);
Destination hcatTopic = session.createTopic("planetlab.hcat");
consumer = session.createConsumer(hcatTopic);
}
use of javax.jms.Destination in project quickstarts by jboss-switchyard.
the class CamelAmqpBindingTest method sentTextToQueue.
private void sentTextToQueue(String payload) throws Exception {
Session session = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Destination destination = _mixin.getDestination(AMQPMixIn.DEFAULT_QUEUE_JNDI_LOCATION);
MessageProducer messageProducer = session.createProducer(destination);
TextMessage message = session.createTextMessage(payload);
messageProducer.send(message);
session.close();
}
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