Package backtype.storm.contrib.jms.spout

Examples of backtype.storm.contrib.jms.spout.JmsSpout


    // JMS Producer
    JmsTupleProducer producer = new JsonTupleProducer();

    // JMS Queue Spout
    JmsSpout queueSpout = new JmsSpout();
    queueSpout.setJmsProvider(jmsQueueProvider);
    queueSpout.setJmsTupleProducer(producer);
    queueSpout.setJmsAcknowledgeMode(Session.CLIENT_ACKNOWLEDGE);
    queueSpout.setDistributed(true); // allow multiple instances

    TopologyBuilder builder = new TopologyBuilder();
   
    // spout with 5 parallel instances
    builder.setSpout(JMS_QUEUE_SPOUT, queueSpout, 5);

    // intermediate bolt, subscribes to jms spout, anchors on tuples, and auto-acks
    builder.setBolt(INTERMEDIATE_BOLT,
        new GenericBolt("INTERMEDIATE_BOLT", true, true, new Fields("json")), 3).shuffleGrouping(
        JMS_QUEUE_SPOUT);

    // bolt that subscribes to the intermediate bolt, and auto-acks
    // messages.
    builder.setBolt(FINAL_BOLT, new GenericBolt("FINAL_BOLT", true, true), 3).shuffleGrouping(
        INTERMEDIATE_BOLT);
   
    // bolt that subscribes to the intermediate bolt, and publishes to a JMS Topic   
    JmsBolt jmsBolt = new JmsBolt();
    jmsBolt.setJmsProvider(jmsTopicProvider);
   
    // anonymous message producer just calls toString() on the tuple to create a jms message
    jmsBolt.setJmsMessageProducer(new JmsMessageProducer() {
      @Override
      public Message toMessage(Session session, Tuple input) throws JMSException{
        System.out.println("Sending JMS Message:" + input.toString());
        TextMessage tm = session.createTextMessage(input.toString());
        return tm;
      }
    });
   
    builder.setBolt(JMS_TOPIC_BOLT, jmsBolt).shuffleGrouping(INTERMEDIATE_BOLT);
   
    // JMS Topic spout
    JmsSpout topicSpout = new JmsSpout();
    topicSpout.setJmsProvider(jmsTopicProvider);
    topicSpout.setJmsTupleProducer(producer);
    topicSpout.setJmsAcknowledgeMode(Session.CLIENT_ACKNOWLEDGE);
    topicSpout.setDistributed(false);
   
    builder.setSpout(JMS_TOPIC_SPOUT, topicSpout);
   
    builder.setBolt(ANOTHER_BOLT, new GenericBolt("ANOTHER_BOLT", true, true), 1).shuffleGrouping(
        JMS_TOPIC_SPOUT);
View Full Code Here

TOP

Related Classes of backtype.storm.contrib.jms.spout.JmsSpout

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.