Search in sources :

Example 6 with Message

use of javax.jms.Message in project qpid by apache.

the class Agent method sendSubscriptionIndicate.

//                               methods implementing SubscribableAgent interface
// ********************************************************************************************************
/**
     * Send a list of updated subscribed data to the Console.
     *
     * @param handle the console reply handle.
     * @param results a list of subscribed data in Map encoded form.
     */
public final void sendSubscriptionIndicate(final Handle handle, final List<Map> results) {
    try {
        Message response = AMQPMessage.createListMessage(_syncSession);
        response.setJMSCorrelationID(handle.getCorrelationId());
        response.setStringProperty("x-amqp-0-10.app-id", "qmf2");
        response.setStringProperty("method", "indication");
        response.setStringProperty("qmf.opcode", "_data_indication");
        response.setStringProperty("qmf.content", "_data");
        response.setStringProperty("qmf.agent", _name);
        response.setStringProperty("qpid.subject", handle.getRoutingKey());
        AMQPMessage.setList(response, results);
        sendResponse(handle, response);
    } catch (JMSException jmse) {
        _log.info("JMSException {} caught in sendSubscriptionIndicate()", jmse.getMessage());
    }
}
Also used : AMQPMessage(org.apache.qpid.qmf2.common.AMQPMessage) MapMessage(javax.jms.MapMessage) Message(javax.jms.Message) JMSException(javax.jms.JMSException)

Example 7 with Message

use of javax.jms.Message in project qpid by apache.

the class Agent method queryResponse.

/**
     * Send the query response back to the Console.
     * @param handle the reply handle that contains the replyTo Address.
     * @param results the list of mapEncoded query results.
     * @param qmfContentType the value to be passed to the qmf.content Header.
     */
protected final void queryResponse(final Handle handle, List<Map> results, final String qmfContentType) {
    try {
        Message response = AMQPMessage.createListMessage(_syncSession);
        response.setJMSCorrelationID(handle.getCorrelationId());
        response.setStringProperty("x-amqp-0-10.app-id", "qmf2");
        response.setStringProperty("method", "response");
        response.setStringProperty("qmf.opcode", "_query_response");
        response.setStringProperty("qmf.agent", _name);
        response.setStringProperty("qmf.content", qmfContentType);
        response.setStringProperty("qpid.subject", handle.getRoutingKey());
        AMQPMessage.setList(response, results);
        sendResponse(handle, response);
    } catch (JMSException jmse) {
        _log.info("JMSException {} caught in queryResponse()", jmse.getMessage());
    }
}
Also used : AMQPMessage(org.apache.qpid.qmf2.common.AMQPMessage) MapMessage(javax.jms.MapMessage) Message(javax.jms.Message) JMSException(javax.jms.JMSException)

Example 8 with Message

use of javax.jms.Message in project qpid by apache.

the class Console method invokeMethod.

/**
     * Invoke the named method on the named Agent.
     * <p>
     * Intended to by called by the AgentProxy. Shouldn't generally be called directly by Console applications.
     *
     * @param agent the Agent to invoke the method on.
     * @param content an unordered set of key/value pairs comprising the method arguments.
     * @param replyHandle the correlation handle used to tie asynchronous method requests with responses
     * @param timeout the time to wait for a reply from the Agent, a value of -1 means use the default timeout
     * @return the method response Arguments in Map form
     */
public MethodResult invokeMethod(final Agent agent, final Map<String, Object> content, final String replyHandle, int timeout) throws QmfException {
    if (!agent.isActive()) {
        throw new QmfException("Called invokeMethod() with inactive agent");
    }
    String agentName = agent.getName();
    timeout = (timeout < 1) ? _replyTimeout : timeout;
    try {
        Destination destination = (replyHandle == null) ? _replyAddress : _asyncReplyAddress;
        MapMessage request = _syncSession.createMapMessage();
        request.setJMSReplyTo(destination);
        request.setJMSCorrelationID(replyHandle);
        request.setStringProperty("x-amqp-0-10.app-id", "qmf2");
        request.setStringProperty("method", "request");
        request.setStringProperty("qmf.opcode", "_method_request");
        request.setStringProperty("qpid.subject", agentName);
        for (Map.Entry<String, Object> entry : content.entrySet()) {
            request.setObject(entry.getKey(), entry.getValue());
        }
        // it would be somewhat unfortunate if their response got interleaved with ours!!
        synchronized (this) {
            _requester.send(request);
            if (replyHandle == null) {
                // If this is a synchronous request get the response
                Message response = _responder.receive(timeout * 1000);
                if (response == null) {
                    _log.info("No response received in invokeMethod()");
                    throw new QmfException("No response received for Console.invokeMethod()");
                }
                MethodResult result = new MethodResult(AMQPMessage.getMap(response));
                QmfException exception = result.getQmfException();
                if (exception != null) {
                    throw exception;
                }
                return result;
            }
        }
        // If this is an asynchronous request return without waiting for a response
        return null;
    } catch (JMSException jmse) {
        _log.info("JMSException {} caught in invokeMethod()", jmse.getMessage());
        throw new QmfException(jmse.getMessage());
    }
}
Also used : Destination(javax.jms.Destination) AMQPMessage(org.apache.qpid.qmf2.common.AMQPMessage) MapMessage(javax.jms.MapMessage) Message(javax.jms.Message) MapMessage(javax.jms.MapMessage) JMSException(javax.jms.JMSException) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) QmfException(org.apache.qpid.qmf2.common.QmfException)

Example 9 with Message

use of javax.jms.Message in project storm by apache.

the class JmsBolt method process.

/**
     * Consumes a tuple and sends a JMS message.
     * <p>
     * If autoAck is true, the tuple will be acknowledged
     * after the message is sent.
     * <p>
     * If JMS sending fails, the tuple will be failed.
     */
@Override
protected void process(Tuple input) {
    // write the tuple to a JMS destination...
    LOG.debug("Tuple received. Sending JMS message.");
    try {
        Message msg = this.producer.toMessage(this.session, input);
        if (msg != null) {
            if (msg.getJMSDestination() != null) {
                this.messageProducer.send(msg.getJMSDestination(), msg);
            } else {
                this.messageProducer.send(msg);
            }
        }
        if (this.autoAck) {
            LOG.debug("ACKing tuple: " + input);
            this.collector.ack(input);
        }
    } catch (JMSException e) {
        // failed to send the JMS message, fail the tuple fast
        LOG.warn("Failing tuple: " + input);
        LOG.warn("Exception: ", e);
        this.collector.fail(input);
    }
}
Also used : Message(javax.jms.Message) JMSException(javax.jms.JMSException)

Example 10 with Message

use of javax.jms.Message 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);
    }
}
Also used : Destination(javax.jms.Destination) MessageConsumer(javax.jms.MessageConsumer) Message(javax.jms.Message) JMSException(javax.jms.JMSException) ConnectionFactory(javax.jms.ConnectionFactory)

Aggregations

Message (javax.jms.Message)191 TextMessage (javax.jms.TextMessage)91 Test (org.junit.Test)84 Session (javax.jms.Session)73 JMSException (javax.jms.JMSException)59 MessageProducer (javax.jms.MessageProducer)53 ObjectMessage (javax.jms.ObjectMessage)46 MessageConsumer (javax.jms.MessageConsumer)40 Connection (javax.jms.Connection)38 BytesMessage (javax.jms.BytesMessage)31 Destination (javax.jms.Destination)27 MapMessage (javax.jms.MapMessage)25 Queue (javax.jms.Queue)20 QueueSession (javax.jms.QueueSession)17 ConnectionFactory (javax.jms.ConnectionFactory)16 MessageCreator (org.springframework.jms.core.MessageCreator)12 MessageListener (javax.jms.MessageListener)9 AMQPMessage (org.apache.qpid.qmf2.common.AMQPMessage)9 Map (java.util.Map)8 QueueConnection (javax.jms.QueueConnection)8