Class JmsBolt

All Implemented Interfaces:
Serializable, IBolt, IComponent, IRichBolt

public class JmsBolt extends BaseTickTupleAwareRichBolt
A JmsBolt receives org.apache.storm.tuple.Tuple objects from a Storm topology and publishes JMS Messages to a destination (topic or queue).

To use a JmsBolt in a topology, the following must be supplied:

  1. A JmsProvider implementation.
  2. A JmsMessageProducer implementation.
The JmsProvider provides the JMS javax.jms.ConnectionFactory and javax.jms.Destination objects requied to publish JMS messages.

The JmsBolt uses a JmsMessageProducer to translate org.apache.storm.tuple.Tuple objects into javax.jms.Message objects for publishing.

Both JmsProvider and JmsMessageProducer must be set, or the bolt will fail upon deployment to a cluster.

The JmsBolt is typically an endpoint in a topology -- in other words it does not emit any tuples.

See Also:
  • Constructor Details

    • JmsBolt

      public JmsBolt()
  • Method Details

    • setJmsProvider

      public void setJmsProvider(JmsProvider provider)
      Set the JmsProvider used to connect to the JMS destination topic/queue.
    • setJmsMessageProducer

      public void setJmsMessageProducer(JmsMessageProducer producer)
      Set the JmsMessageProducer used to convert tuples into JMS messages.
    • setJmsAcknowledgeMode

      public void setJmsAcknowledgeMode(int acknowledgeMode)
      Sets the JMS acknowledgement mode for JMS messages sent by this bolt.

      Possible values:

      • javax.jms.Session.AUTO_ACKNOWLEDGE
      • javax.jms.Session.CLIENT_ACKNOWLEDGE
      • javax.jms.Session.DUPS_OK_ACKNOWLEDGE
      Parameters:
      acknowledgeMode - (constant defined in javax.jms.Session)
    • setAutoAck

      public void setAutoAck(boolean autoAck)
      Sets whether or not tuples should be acknowledged by this bolt.
    • process

      protected void process(Tuple input)
      Consumes a tuple and sends a JMS message.

      If autoAck is true, the tuple will be acknowledged after the message is sent.

      If JMS sending fails, the tuple will be failed.

      Specified by:
      process in class BaseTickTupleAwareRichBolt
      Parameters:
      input - The input tuple to be processed.
    • cleanup

      public void cleanup()
      Releases JMS resources.
      Specified by:
      cleanup in interface IBolt
      Overrides:
      cleanup in class BaseRichBolt
    • declareOutputFields

      public void declareOutputFields(OutputFieldsDeclarer declarer)
      Description copied from interface: IComponent
      Declare the output schema for all the streams of this topology.
      Parameters:
      declarer - this is used to declare output stream ids, output fields, and whether or not each output stream is a direct stream
    • prepare

      public void prepare(Map<String,Object> topoConf, TopologyContext context, OutputCollector collector)
      Initializes JMS resources.
      Parameters:
      topoConf - The Storm configuration for this bolt. This is the configuration provided to the topology merged in with cluster configuration on this machine.
      context - This object can be used to get information about this task's place within the topology, including the task id and component id of this task, input and output information, etc.
      collector - The collector is used to emit tuples from this bolt. Tuples can be emitted at any time, including the prepare and cleanup methods. The collector is thread-safe and should be saved as an instance variable of this bolt object.