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.
| 限定符和类型 | 字段和说明 |
|---|---|
protected boolean |
autoAck |
protected com.rabbitmq.client.Channel |
channel |
protected com.rabbitmq.client.Connection |
connection |
protected org.apache.flink.streaming.connectors.rabbitmq.QueueingConsumer |
consumer |
protected RMQDeserializationSchema<OUT> |
deliveryDeserializer |
protected String |
queueName |
| 构造器和说明 |
|---|
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,
boolean usesCorrelationId,
RMQDeserializationSchema<OUT> deliveryDeserializer)
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.
|
RMQSource(RMQConnectionConfig rmqConnectionConfig,
String queueName,
RMQDeserializationSchema<OUT> deliveryDeserializer)
Creates a new RabbitMQ source with at-least-once message processing guarantee when
checkpointing is enabled.
|
| 限定符和类型 | 方法和说明 |
|---|---|
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.Connection |
setupConnection()
Initializes the connection to RMQ using the default connection factory from
setupConnectionFactory(). |
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, notifyCheckpointAborted, notifyCheckpointCompleteprotected final String queueName
protected RMQDeserializationSchema<OUT> deliveryDeserializer
protected transient com.rabbitmq.client.Connection connection
protected transient com.rabbitmq.client.Channel channel
protected transient org.apache.flink.streaming.connectors.rabbitmq.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.public RMQSource(RMQConnectionConfig rmqConnectionConfig, String queueName, RMQDeserializationSchema<OUT> deliveryDeserializer)
For exactly-once, please use the constructor RMQSource(RMQConnectionConfig, String, boolean, RMQDeserializationSchema).
It also uses the provided RMQDeserializationSchema to parse both the correlationID
and the message.
rmqConnectionConfig - The RabbiMQ connection configuration RMQConnectionConfig.queueName - The queue to receive messages from.deliveryDeserializer - A RMQDeserializationSchema for parsing the RMQDelivery.public RMQSource(RMQConnectionConfig rmqConnectionConfig, String queueName, boolean usesCorrelationId, RMQDeserializationSchema<OUT> deliveryDeserializer)
It also uses the provided RMQDeserializationSchema to parse both the correlationID
and the message.
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.deliveryDeserializer - A RMQDeserializationSchema for parsing the RMQDelivery.protected com.rabbitmq.client.ConnectionFactory setupConnectionFactory()
throws Exception
ConnectionFactory.Exception@VisibleForTesting
protected com.rabbitmq.client.Connection setupConnection()
throws Exception
setupConnectionFactory(). The user may override this method to setup and configure their
own Connection.Exception@VisibleForTesting
protected 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 在接口中 org.apache.flink.streaming.api.functions.source.SourceFunction<OUT>Copyright © 2014–2021 The Apache Software Foundation. All rights reserved.