我试图了解如何在Flink中使用RabbiMQ的高可用性,使用Correlation Ids并启用Checkpoints,但它无效。我的制片人代码:
connection = factory.newConnection();
Channel channel = connection.createChannel();
String corrId = java.util.UUID.randomUUID().toString();
BasicProperties props = new AMQP.BasicProperties().builder().correlationId(corrId).build();
channel.queueDeclare("flink-poc", true, false, false, null);
MessageQueue queue = new MessageQueue(500); //Queue of messages to be sent to rabbitmq
Message msg = null;
while ((msg = queue.takeMessage()) != null)
channel.basicPublish("", "flink-poc", props, mapper.writeValueAsBytes(msg));
channel.close();
connection.close();
消费者代码:
StreamExecutionEnvironment env = StreamExecutionEnvironment
.getExecutionEnvironment();
env.setBufferTimeout(100);
env.enableCheckpointing(1000,CheckpointingMode.EXACTLY_ONCE); // start a checkpoint every 1000 ms
env.setStreamTimeCharacteristic(TimeCharacteristic.EventTime);
RabbitSource<Message> rabbitSource = new RabbitSource<Message>(Host, 5672, username, pass, "flink-poc", VirtualHost, true, schema);
messages = env.addSource(rabbitSource, TypeInformation.of(Message.class)
使用此代码,不会向RabbitMQ返回ACK。任何帮助表示赞赏。
更新:使用预取(channel.basicQos(15);
),它会开始工作,但速率非常低。有没有办法改善它?如果取消激活setStreamTimeCharacteristic
,则会对结果进行排序并将速率提高10倍,但速率仍然非常低,这怎么可能?
答案 0 :(得分:2)
您对所有邮件使用相同的correlationId,您必须为每条邮件使用一个新的邮件。从https://ci.apache.org/projects/flink/flink-docs-master/api/java/org/apache/flink/streaming/connectors/rabbitmq/RMQSource.html&#39; usesCorrelationId - 收到的消息是否提供了唯一ID以进行重复数据删除消息(如果确认失败)。仅在启用了检查点时使用。&#39;