SpringJmsProvider object given the name of a
15 | * classpath resource (the spring application context file), and the bean
16 | * names of a JMS connection factory and destination.
17 | *
18 | * @param context - the spring configuration file (classpath resource)
19 | * @param connectionFactoryBean - the JMS connection factory bean name
20 | * @param destinationBean - the JMS destination bean name
21 | */
22 | public SpringJmsProvider(ApplicationContext context, String connectionFactoryBean, String destinationBean) {
23 | this.connectionFactory = (ConnectionFactory) context.getBean(connectionFactoryBean);
24 | this.destination = (Destination) context.getBean(destinationBean);
25 | }
26 |
27 | public ConnectionFactory connectionFactory() throws Exception {
28 | return this.connectionFactory;
29 | }
30 |
31 | public Destination destination() throws Exception {
32 | return this.destination;
33 | }
34 |
35 | }
--------------------------------------------------------------------------------
/feeder/src/main/java/nl/avisi/feeder/RandomWordFeeder.java:
--------------------------------------------------------------------------------
1 | package nl.avisi.feeder;
2 |
3 | import backtype.storm.spout.SpoutOutputCollector;
4 | import backtype.storm.task.TopologyContext;
5 | import backtype.storm.topology.OutputFieldsDeclarer;
6 | import backtype.storm.topology.base.BaseRichSpout;
7 | import backtype.storm.tuple.Fields;
8 | import backtype.storm.tuple.Values;
9 | import backtype.storm.utils.Utils;
10 |
11 | import java.util.Map;
12 | import java.util.Random;
13 |
14 | /**
15 | * @author robbreuk
16 | * @author Prashanth
17 | */
18 | public final class RandomWordFeeder extends BaseRichSpout {
19 |
20 | private static final String[] COMPANIES = new String[]{
21 | "Google", "Apple", "BlackBerry", "Microsoft", "Amazon", "Motorola", "HTC", "Samsung", "Nokia", "LG", "Sony", "Dell",
22 | "ASUS", "ACER", "ZTE"};
23 | private static final long serialVersionUID = 5617224155226323658L;
24 | private SpoutOutputCollector collector;
25 | private Random random;
26 |
27 | @Override
28 | public final void open(final Map map, final TopologyContext topologyContext, final SpoutOutputCollector collector) {
29 | this.collector = collector;
30 | this.random = new Random();
31 | }
32 |
33 | @Override
34 | public final void nextTuple() {
35 | Utils.sleep(200);
36 | collector.emit(new Values(COMPANIES[random.nextInt(COMPANIES.length)]));
37 | }
38 |
39 | @Override
40 | public final void declareOutputFields(final OutputFieldsDeclarer declarer) {
41 | declarer.declare(new Fields("word"));
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/runner/src/main/resources/applicationContext.xml:
--------------------------------------------------------------------------------
1 |
2 | GenericBolt instance.
23 | *
24 | * @param name The name of the bolt (used in DEBUG logging)
25 | * @param autoAck Whether or not this bolt should automatically acknowledge received tuples.
26 | * @param autoAnchor Whether or not this bolt should automatically anchor to received tuples.
27 | * @param declaredFields The fields this bolt declares as output.
28 | */
29 | public GenericBolt(String name, boolean autoAck, boolean autoAnchor, Fields declaredFields) {
30 | this.name = name;
31 | this.autoAck = autoAck;
32 | this.autoAnchor = autoAnchor;
33 | this.declaredFields = declaredFields;
34 | }
35 |
36 | public GenericBolt(String name, boolean autoAck, boolean autoAnchor) {
37 | this(name, autoAck, autoAnchor, null);
38 | }
39 |
40 | @SuppressWarnings("rawtypes")
41 | public void prepare(Map stormConf, TopologyContext context,
42 | OutputCollector collector) {
43 | this.collector = collector;
44 |
45 | }
46 |
47 | public void execute(Tuple input) {
48 | System.out.println("[" + this.name + "] Received message: " + input);
49 |
50 |
51 | // only emit if we have declared fields.
52 | if (this.declaredFields != null) {
53 | System.out.println("[" + this.name + "] emitting: " + input);
54 | if (this.autoAnchor) {
55 | this.collector.emit(input, input.getValues());
56 | } else {
57 | this.collector.emit(input.getValues());
58 | }
59 | }
60 |
61 | if (this.autoAck) {
62 | System.out.println("[" + this.name + "] ACKing tuple: " + input);
63 | this.collector.ack(input);
64 | }
65 |
66 | }
67 |
68 | public void cleanup() {
69 |
70 | }
71 |
72 | public void declareOutputFields(OutputFieldsDeclarer declarer) {
73 | if (this.declaredFields != null) {
74 | declarer.declare(this.declaredFields);
75 | }
76 | }
77 |
78 | public boolean isAutoAck() {
79 | return this.autoAck;
80 | }
81 |
82 | public void setAutoAck(boolean autoAck) {
83 | this.autoAck = autoAck;
84 | }
85 |
86 | }
--------------------------------------------------------------------------------
/feeder/feeder.eml:
--------------------------------------------------------------------------------
1 |
2 |