我使用了Apache Bahir的AMQSource连接器来监听ActiveMQ,但是当我运行Flink作业以使用ActiveMQ中的数据时,不会生成任何输出。
例如,连接器正在侦听包含4条消息的ActiveMQ,但是当我运行Flink作业时,不会消耗任何数据。
val brokerURL = "tcp://localhost:61616"
val destinationName = "TEST.FOO"
val filePath = "C:\\output" + System.currentTimeMillis + ".csv"
val env = StreamExecutionEnvironment.getExecutionEnvironment
env.setStateBackend(new MemoryStateBackend(1000, false))
val config = new AMQSourceConfig.AMQSourceConfigBuilder[String]()
.setConnectionFactory(new ActiveMQConnectionFactory(brokerURL))
.setDestinationName(destinationName)
.setDeserializationSchema(new SimpleStringSchema)
.setDestinationType(DestinationType.QUEUE)
.setRunningChecker(new RunningChecker).build
val amqSource = new AMQSource[String](config)
val stream = env.addSource(amqSource)
stream.map(/*Some MapFunction*/)
stream.writeAsText(filePath)
stream.print
env.execute
答案 0 :(得分:0)
AMQSource希望消息以字节为单位,请参见AMQSource.class下run方法的代码:
Message message = this.consumer.receive(1000L);
if (!(**message instanceof BytesMessage**)) {
LOG.warn("Active MQ source received non bytes message: {}", message);
return;
}
当向ActiveMQ生成数据而不是文本消息时:
val message = session.createTextMessage(text)
使用字节消息:
val message = session.createBytesMessage()
message.writeBytes(text.getBytes)