OUT - The type of the data read from RabbitMQ.public class RMQSource<OUT> extends org.apache.flink.streaming.api.functions.source.MultipleIdsMessageAcknowledgingSourceBase<OUT,String,Long> implements org.apache.flink.api.java.typeutils.ResultTypeQueryable<OUT>
RabbitMQ requires messages to be acknowledged. On failures, RabbitMQ will re-resend all messages
which have not been acknowledged previously. When a failure occurs directly after a completed
checkpoint, all messages part of this checkpoint might be processed again because they couldn't
be acknowledged before failure. This case is handled by the MessageAcknowledgingSourceBase
base class which deduplicates the messages using the correlation id.
RabbitMQ's Delivery Tags do NOT represent unique ids / offsets. That's why the source uses the Correlation ID in the message properties to check for duplicate messages. Note that the correlation id has to be set at the producer. If the correlation id is not set, messages may be produced more than once in corner cases.
This source can be operated in three different modes:
1) Exactly-once (when checkpointed) with RabbitMQ transactions and messages with unique correlation IDs. 2) At-least-once (when checkpointed) with RabbitMQ transactions but no deduplication mechanism (correlation id is not set). 3) No strong delivery guarantees (without checkpointing) with RabbitMQ auto-commit mode.
Users may overwrite the setupConnectionFactory() method to pass their setup their own ConnectionFactory in case the constructor parameters are not sufficient.
| Modifier and Type | Field and Description |
|---|---|
protected boolean |
autoAck |
protected com.rabbitmq.client.Channel |
channel |
protected com.rabbitmq.client.Connection |
connection |
protected com.rabbitmq.client.QueueingConsumer |
consumer |
protected String |
queueName |
protected org.apache.flink.api.common.serialization.DeserializationSchema<OUT> |
schema |
| Constructor and Description |
|---|
RMQSource(RMQConnectionConfig rmqConnectionConfig,
String queueName,
boolean usesCorrelationId,
org.apache.flink.api.common.serialization.DeserializationSchema<OUT> deserializationSchema)
Creates a new RabbitMQ source.
|
RMQSource(RMQConnectionConfig rmqConnectionConfig,
String queueName,
org.apache.flink.api.common.serialization.DeserializationSchema<OUT> deserializationSchema)
Creates a new RabbitMQ source with at-least-once message processing guarantee when
checkpointing is enabled.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
acknowledgeSessionIDs(List<Long> sessionIds) |
void |
cancel() |
void |
close() |
org.apache.flink.api.common.typeinfo.TypeInformation<OUT> |
getProducedType() |
void |
open(org.apache.flink.configuration.Configuration config) |
void |
run(org.apache.flink.streaming.api.functions.source.SourceFunction.SourceContext<OUT> ctx) |
protected com.rabbitmq.client.ConnectionFactory |
setupConnectionFactory()
Initializes the connection to RMQ with a default connection factory.
|
protected void |
setupQueue()
Sets up the queue.
|
acknowledgeIDs, snapshotStateaddId, initializeState, notifyCheckpointCompleteprotected final String queueName
protected org.apache.flink.api.common.serialization.DeserializationSchema<OUT> schema
protected transient com.rabbitmq.client.Connection connection
protected transient com.rabbitmq.client.Channel channel
protected transient com.rabbitmq.client.QueueingConsumer consumer
protected transient boolean autoAck
public RMQSource(RMQConnectionConfig rmqConnectionConfig, String queueName, org.apache.flink.api.common.serialization.DeserializationSchema<OUT> deserializationSchema)
For exactly-once, please use the constructor
RMQSource(RMQConnectionConfig, String, boolean, DeserializationSchema).
rmqConnectionConfig - The RabbiMQ connection configuration RMQConnectionConfig.queueName - The queue to receive messages from.deserializationSchema - A DeserializationSchema for turning the bytes received
into Java objects.public RMQSource(RMQConnectionConfig rmqConnectionConfig, String queueName, boolean usesCorrelationId, org.apache.flink.api.common.serialization.DeserializationSchema<OUT> deserializationSchema)
rmqConnectionConfig - The RabbiMQ connection configuration RMQConnectionConfig.queueName - The queue to receive messages from.usesCorrelationId - Whether the messages received are supplied with a unique
id to deduplicate messages (in case of failed acknowledgments).
Only used when checkpointing is enabled.deserializationSchema - A DeserializationSchema for turning the bytes received
into Java objects.protected com.rabbitmq.client.ConnectionFactory setupConnectionFactory()
throws Exception
Exceptionprotected void setupQueue()
throws IOException
IOExceptionpublic void open(org.apache.flink.configuration.Configuration config)
throws Exception
public void close()
throws Exception
public void run(org.apache.flink.streaming.api.functions.source.SourceFunction.SourceContext<OUT> ctx) throws Exception
public void cancel()
cancel in interface org.apache.flink.streaming.api.functions.source.SourceFunction<OUT>Copyright © 2014–2018 The Apache Software Foundation. All rights reserved.