|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.rapportive.storm.spout.AMQPSpout
public class AMQPSpout
Spout to feed messages into Storm from an AMQP queue. Each message routed to the queue will be emitted as a Storm tuple. The message will be acked or rejected once the topology has respectively fully processed or failed the corresponding tuple.
N.B. if you need to guarantee all messages are reliably
processed, you should have AMQPSpout consume from a queue that is
not set as 'exclusive' or 'auto-delete': otherwise if the spout
task crashes or is restarted, the queue will be deleted and any messages in
it lost, as will any messages published while the task remains down. See
SharedQueueWithBinding to declare a shared
queue that allows for guaranteed processing. (For prototyping, an
ExclusiveQueueWithBinding may be
simpler to manage.)
N.B. this does not currently handle malformed messages
(which cannot be deserialised by the provided Scheme) very well:
the spout worker will crash if it fails to serialise a message.
This consumes messages from AMQP asynchronously, so it may receive
messages before Storm requests them as tuples; therefore it buffers messages
in an internal queue. To avoid this buffer growing large and consuming too
much RAM, set CONFIG_PREFETCH_COUNT.
This spout can be distributed among multiple workers, depending on the
queue declaration: see QueueDeclaration.isParallelConsumable().
QueueDeclaration,
SharedQueueWithBinding,
ExclusiveQueueWithBinding,
Serialized Form| Field Summary | |
|---|---|
static String |
CONFIG_PREFETCH_COUNT
Storm config key to set the AMQP basic.qos prefetch-count parameter. |
static long |
WAIT_AFTER_SHUTDOWN_SIGNAL
Time in milliseconds to wait after losing connection to the AMQP broker before attempting to reconnect. |
static long |
WAIT_FOR_NEXT_MESSAGE
Time in milliseconds to wait for a message from the queue if there is no message ready when the topology requests a tuple (via nextTuple()). |
| Constructor Summary | |
|---|---|
AMQPSpout(String host,
int port,
String username,
String password,
String vhost,
QueueDeclaration queueDeclaration,
Scheme scheme)
Create a new AMQP spout. |
|
AMQPSpout(String host,
int port,
String username,
String password,
String vhost,
QueueDeclaration queueDeclaration,
Scheme scheme,
boolean requeueOnFail)
Create a new AMQP spout. |
|
| Method Summary | |
|---|---|
void |
ack(Object msgId)
Acks the message with the AMQP broker. |
void |
activate()
Resumes a paused spout |
void |
close()
Cancels the queue subscription, and disconnects from the AMQP broker. |
void |
deactivate()
Pauses the spout |
void |
declareOutputFields(OutputFieldsDeclarer declarer)
Declares the output fields of this spout according to the provided Scheme. |
void |
fail(Object msgId)
Tells the AMQP broker to drop (Basic.Reject) the message. |
Map<String,Object> |
getComponentConfiguration()
|
void |
nextTuple()
Emits the next message from the queue as a tuple. |
void |
open(Map config,
TopologyContext context,
SpoutOutputCollector collector)
Connects to the AMQP broker, declares the queue and subscribes to incoming messages. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final String CONFIG_PREFETCH_COUNT
This caps the number of messages outstanding (i.e. unacked) at a time that will be sent to each spout worker. Increasing this will improve throughput if the network roundtrip time to the AMQP broker is significant compared to the time for the topology to process each message; this will also increase the RAM requirements as the internal message buffer grows.
AMQP allows a prefetch-count of zero, indicating unlimited delivery, but that is not allowed here to avoid unbounded buffer growth.
public static final long WAIT_FOR_NEXT_MESSAGE
nextTuple()).
public static final long WAIT_AFTER_SHUTDOWN_SIGNAL
| Constructor Detail |
|---|
public AMQPSpout(String host,
int port,
String username,
String password,
String vhost,
QueueDeclaration queueDeclaration,
Scheme scheme)
open(Map, TopologyContext, SpoutOutputCollector) is called, it
will declare a queue according to the specified
queueDeclaration, subscribe to the queue, and start consuming
messages. It will use the provided scheme to deserialise each
AMQP message into a Storm tuple. Note that failed messages will not be
requeued.
host - hostname of the AMQP broker nodeport - port number of the AMQP broker nodeusername - username to log into to the brokerpassword - password to authenticate to the brokervhost - vhost on the brokerqueueDeclaration - declaration of the queue / exchange bindingsscheme - Scheme used to deserialise
each AMQP message into a Storm tuple
public AMQPSpout(String host,
int port,
String username,
String password,
String vhost,
QueueDeclaration queueDeclaration,
Scheme scheme,
boolean requeueOnFail)
open(Map, TopologyContext, SpoutOutputCollector) is called, it
will declare a queue according to the specified
queueDeclaration, subscribe to the queue, and start consuming
messages. It will use the provided scheme to deserialise each
AMQP message into a Storm tuple.
host - hostname of the AMQP broker nodeport - port number of the AMQP broker nodeusername - username to log into to the brokerpassword - password to authenticate to the brokervhost - vhost on the brokerqueueDeclaration - declaration of the queue / exchange bindingsscheme - Scheme used to deserialise
each AMQP message into a Storm tuplerequeueOnFail - whether messages should be requeued on failure| Method Detail |
|---|
public void ack(Object msgId)
ack in interface ISpoutpublic void close()
close in interface ISpoutpublic void activate()
activate in interface ISpoutpublic void deactivate()
deactivate in interface ISpoutpublic void fail(Object msgId)
N.B. There's a potential for infinite redelivery in the event of non-transient failures (e.g. malformed messages).
fail in interface ISpoutpublic void nextTuple()
If no message is ready to emit, this will wait a short time
(WAIT_FOR_NEXT_MESSAGE) for one to arrive on the queue,
to avoid a tight loop in the spout worker.
nextTuple in interface ISpout
public void open(Map config,
TopologyContext context,
SpoutOutputCollector collector)
open in interface ISpoutpublic void declareOutputFields(OutputFieldsDeclarer declarer)
Scheme.
declareOutputFields in interface IComponentpublic Map<String,Object> getComponentConfiguration()
getComponentConfiguration in interface IComponent
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||