【问题标题】:Reading TCP raw data and send it to ActiveMQ读取 TCP 原始数据并将其发送到 ActiveMQ
【发布时间】:2015-09-17 20:27:57
【问题描述】:

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

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

【问题讨论】:

  • 感谢 Lalit,我之前看过它,但它似乎基于 Grails 2.x 或更低版本并且工作正常,但我使用的是基于 Spring Boot 并使用 gradle 的 Grails 3.0.4 .他们在这个版本中改变了很多东西,如果没有操作方法,普通配置似乎不再起作用

标签: grails spring-boot apache-camel activemq


【解决方案1】:

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

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()

注意。我遗漏了不影响此答案的某些代码部分。如果你有这些,那么你很高兴。

【讨论】:

    猜你喜欢
    • 2012-08-16
    • 1970-01-01
    • 2011-03-01
    • 2011-02-26
    • 2012-08-26
    • 1970-01-01
    • 1970-01-01
    • 2012-04-08
    • 2021-09-21
    相关资源
    最近更新 更多