I used Apache Bahir's AMQSource connector that listens to ActiveMQ, but when I run the Flink job to consume the data from ActiveMQ no output is generated.
For example, the connector is listening to ActiveMQ which contains 4 messages, but when I run the Flink job no data get consumed.
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
AMQSource expects message as bytes, see code from run method under AMQSource.class:
Message message = this.consumer.receive(1000L);
if (!(**message instanceof BytesMessage**)) {
LOG.warn("Active MQ source received non bytes message: {}", message);
return;
}
When produce data to ActiveMQ instead of text message:
val message = session.createTextMessage(text)
Use bytes message:
val message = session.createBytesMessage()
message.writeBytes(text.getBytes)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.