读取 TCP 原始数据并将其发送到 ActiveMQ

Reading TCP raw data and send it to ActiveMQ

我想编写一个应用程序,从发送字节码的固定单元控制器读取跟踪数据并处理数据,然后写入数据库。我想使用 grails 3.0.4、ActiveMQ、Apache Camel。如果我将数据从控制器直接发送到 ActiveMQ,我会收到一个数据类型错误和建议,我应该在哪里使用 apache camel 来接收然后路由消息。

我知道如何在 grails 项目中设置 apache camel。任何人都可以帮助设置 Apache Camel 以从 grails 3 中的 tcp 读取原始数据所需的步骤。

这就是我实施解决方案的方式:

In build.gradle under dependencies add the following dependencies depending on the components you want to use as follows.

runtime "org.apache.camel:camel-core:2.15.3" runtime "org.apache.camel:camel-groovy:2.15.3" runtime "org.apache.camel:camel-stream:2.15.3" //runtime "org.apache.camel:camel-netty:2.15.3" runtime "org.apache.camel:camel-netty4:2.15.3" runtime "org.apache.camel:camel-spring:2.15.3" runtime "org.apache.camel:camel-jms:2.15.3" runtime "org.apache.activemq:activemq-camel:5.11.1" runtime "org.apache.activemq:activemq-pool:5.11.1"

Create a route that extends RouteBuilder as follows:

class TrackingMessageRoute extends RouteBuilder { def grailsApplication

@Override
void configure() {
    def config = grailsApplication?.config
    //from('netty4:tcp://192.168.254.3:553?sync=true&decoders=#decoders&encoder=#encoder').to('activemq:queue:Mimacs.Tracking.Queue')
    from('netty4:tcp://192.168.254.3:553?serverInitializerFactory=#sif&keepAlive=true&sync=true&allowDefaultCodec=false').to('activemq:queue:Mimacs.Tracking.Queue')
    from('activemq:queue:Mimacs.Tracking.Queue').bean(MimacsMessageListener.class)
}

}

Configure a Camel Context in BootStrap.groovy. You can use SpringBeans in resources.groovy if you want

CamelContext camelContext = new DefaultCamelContext(registry) camelContext.addComponent("activemq", ActiveMQComponent.activeMQComponent("failover:tcp://localhost:61616")) camelContext.addRoutes new TrackingMessageRoute() camelContext.start()

注意。我遗漏了不影响此答案的某些代码部分。如果你有这些,那么你就可以开始了。