标签: apache-camel

Camel:如何在&URI(不作为分隔符)中包含&符作为数据?

(骆驼2.9.2)

非常简单的用例,但我似乎无法找到答案.我的代码归结为:

String user = "user";
String password = "foo&bar";

String uri = "smtp://hostname:25?username=" + user +
    "&password=" + password + 
    "&to=somthing@something.com"; // etc. You get the idea

from("seda:queue:myqueue").to(uri);
Run Code Online (Sandbox Code Playgroud)

Camel抛出ResolveEndpointFailedException并显示"Unknown parameters = [{bar = null}]".

如果我尝试"foo%26bar",我会得到相同的结果.

如果我尝试"foo& bar",骆驼会回答"未知参数= [{amp; bar = null}]."

我尝试使用URISupport创建URI.它将&转移到%26,然后我再次得到"Unknown parameters = [{bar = null}]".

有任何想法吗?

java apache-camel

6
推荐指数
2
解决办法
2423
查看次数

使用ActiveMQ,Camel和Spring实现Request-Reply模式

我正在尝试实现以下功能:

然后逐行读取CSV文件:

  1. 根据该行包含的值构建请求
  2. 将请求发送到消息队列
  3. 其他组件需要获取消息,处理请求并将响应发送到另一个消息队列(生产者已知,因此生产者可以获取响应).

我相信请求 - 回复模式适合该法案.我安装了ActiveMQ,下载了camel并尝试使用他们的jms项目.

配置组件,队列和测试连接(工作)后,我试图弄清楚实际上如何实现请求 - 回复?我没有找到任何好的例子

我有一个RouteBuilder

RouteBuilder

public class MyRouteBuilder extends RouteBuilder {
    public static void main(String[] args) throws Exception {
        new Main().run(args);
    }

    public void configure() {
        from("file:src/data?noop=true")
        .to("activemq:RequestQ");

        from("activemq:RequestQ?exchangePattern=InOut&timeToLive=5000") 
        .inOut("activemq:RequestQ", "bean:myBean?method=someMethod"); 
    }
}
Run Code Online (Sandbox Code Playgroud)

骆驼的context.xml

<beans xmlns="http://www.springframework.org/schema/beans"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="
         http://www.springframework.org/schema/beans 
         http://www.springframework.org/schema/beans/spring-beans.xsd
         http://camel.apache.org/schema/spring
         http://camel.apache.org/schema/spring/camel-spring.xsd">

    <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
        <package>org.apache.camel.example.spring</package>
    </camelContext>

    <bean id="jmsConnectionFactory" 
        class="org.apache.activemq.ActiveMQConnectionFactory">
        <property name="brokerURL" value="tcp://localhost:61616" />
    </bean>

    <bean id="pooledConnectionFactory" 
        class="org.apache.activemq.pool.PooledConnectionFactory" 
        init-method="start" destroy-method="stop">
        <property name="maxConnections" value="8" />
        <property name="connectionFactory" ref="jmsConnectionFactory" />
    </bean> …
Run Code Online (Sandbox Code Playgroud)

java activemq-classic design-patterns jms apache-camel

6
推荐指数
1
解决办法
9908
查看次数

如何将Camel属性加载到Bean中?

我一直在阅读Camel属性的以下页面:http://camel.apache.org/using-propertyplaceholder.html 并阅读"Camel In Action"一书.

我发现"Camel In Action"的第6章在定义Camel属性方面非常有用,我可以从config.properties加载以下三个属性:

config.timeout=10000
config.numSamples=1000
config.defaultViz=a
Run Code Online (Sandbox Code Playgroud)

当我运行我的Java代码时,我能够在applicationContext.xml中的camel路由中看到以下三个值,如下面的线程#0消息所示:

14669 [Camel (HelloWorldContext) thread #0 - timer://hello.world.request.timer] INFO  route1  - printing values read from config.properties file
14669 [Camel (HelloWorldContext) thread #0 - timer://hello.world.request.timer] INFO  route1  - config.timeout= 10000
14669 [Camel (HelloWorldContext) thread #0 - timer://hello.world.request.timer] INFO  route1  - config.numSamples= 1000
14670 [Camel (HelloWorldContext) thread #0 - timer://hello.world.request.timer] INFO  route1  - config.defaultViz= a
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试将变量{{config.defaultViz}}传递给我的SensorGenerator Java类中名为defaultViz的String,并打印该字符串时,我在控制台上获得"{{config.defaultViz}}"而不是包含的值在{{config.defaultViz}}内.

换句话说,这就是我在屏幕上看到的内容:

Returning List
defaultViz= {{config.defaultViz}}
Run Code Online (Sandbox Code Playgroud)

但我真的想在屏幕上看到这个:

Returning List
defaultViz=a
Run Code Online (Sandbox Code Playgroud)

那么我在applicationContext.xml中做错了什么?

更新:问题是我需要在Spring和Camel之间添加一个Bridge,如上面引用的链接中所述.

这是我的UPDATED …

java xml properties apache-camel notation

6
推荐指数
1
解决办法
1万
查看次数

从camel连接到WebSphere MQ服务器时出现"未定义远程通道"问题

我已经配置了两个服务器,一个Active MQ和一个WebSphere MQ 8.0,为了相互通信我在中间配置了一个Apache Camel,它从Active MQ接收消息并将它们发送到WebSphere.现在,Camel能够从Active MQ服务器接收消息,但是当它尝试将它们发送到WebSphere MQ时,它会抛出错误:

引起:com.ibm.mq.jmqi.JmqiException:CC = 2; RC = 2540; AMQ9204:与主机'10 .0.0.122(1414)的连接被拒绝.[1 = com.ibm.mq.jmqi.JmqiException [CC = 2; RC = 2540; AMQ9520:未远程定义通道.[3 = channel.test]],3 = 10.0.0.122(1414),5 = RemoteConnection.analyseErrorSegment]

我能够将Camel与用户连接到WebSphere QueueManager,但不能创建通道,为了连接到WebSphere服务器,camel端的配置是:

    <bean id="weblogicConnectionFactory"
       class="com.ibm.mq.jms.MQConnectionFactory">
   <property name="hostName" value="10.0.0.122"/>
   <property name="port" value="1414"/>
   <property name="queueManager" value="TESTQ"/>
   <property name="channel" value="channel.test"/>
   <property name="transportType" value="1"/>
 </bean>

 <bean id="myProxyConnectionFactory" class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter">
   <property name="targetConnectionFactory" ref="weblogicConnectionFactory"/>
   <property name="username" value="administrator"/>
   <property name="password" value="control123!"/>
  </bean>

 <bean id="weblogicConfig"
       class="org.apache.camel.component.jms.JmsConfiguration">
   <property name="connectionFactory" ref="weblogicConnectionFactory"/>
   <property name="concurrentConsumers" value="10"/>
 </bean>

 <bean id="weblogic"
       class="org.apache.camel.component.jms.JmsComponent">
   <property name="configuration" …
Run Code Online (Sandbox Code Playgroud)

jms channel apache-camel ibm-mq

6
推荐指数
1
解决办法
5884
查看次数

Apache Camel:Aws-S3使用者在连接池超时时启动失败

我正在使用AWS-S3使用者定期轮询S3上某个位置的文件.轮询一定时间之后,它会因为给出的异常而失败

Will try again at next poll. Caused by:[com.amazonaws.AmazonClientException - Unable to execute HTTP request:
Timeout waiting for connection from pool]
com.amazonaws.AmazonClientException: Unable to execute HTTP request:Timeout waiting for connection from pool
at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:376) ~[aws-java-sdk-1.5.5.jar:na]
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:202) ~[aws-java-sdk-1.5.5.jar:na]
at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:3037) ~[aws-java-sdk-1.5.5.jar:na]
at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:3008) ~[aws-java-sdk-1.5.5.jar:na]
at com.amazonaws.services.s3.AmazonS3Client.listObjects(AmazonS3Client.java:531) ~[aws-java-sdk-1.5.5.jar:na]
at org.apache.camel.component.aws.s3.S3Consumer.poll(S3Consumer.java:69) ~[camel-aws-2.12.0.jar:2.12.0]
at org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:187) [camel-core-2.12.0.jar:2.12.0]
at org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:114) [camel-core-2.12.0.jar:2.12.0]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) [na:1.7.0_60]
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304) [na:1.7.0_60]
Run Code Online (Sandbox Code Playgroud)

根据我的理解,原因是消费者耗尽了池中的可用连接,因为它在每次轮询时使用新连接.我需要知道的是如何在每次轮询后释放资源以及为什么组件本身不会这样做.

骆驼版:2.12

编辑:我修改了使用者以选择具有特定连接超时,maxconnections,maxerrorretry和sockettimeout的自定义S3客户端,但没有用.结果是一样的.

S3客户端配置:

ClientConfiguration clientConfiguration = new ClientConfiguration();
    clientConfiguration.setMaxConnections(50);
    clientConfiguration.setConnectionTimeout(6000);
    clientConfiguration.setMaxErrorRetry(3);
    clientConfiguration.setSocketTimeout(30000);
    main.bind("s3Client", new AmazonS3Client(awsCredentials, clientConfiguration));
Run Code Online (Sandbox Code Playgroud)

名为"s3Client"的AmazonS3Client对象与Camel上下文绑定,并提供给基于Camel …

java amazon-s3 apache-camel

6
推荐指数
1
解决办法
2152
查看次数

如何以最少的内存运行spring boot胖子?

这是我们的Maven MediSpan项目。实际上,这是一个RESTWeb服务。JSON通过GPI代码针对指定患者的“ 药物相互作用”查询的返回对象。这是一个剩余查询的示例:

http://localhost:8017/mspn/query?pid=1000&
gpis=83-20-00-30-20-03-10&gpis=64-99-10-02-12-03-20
Run Code Online (Sandbox Code Playgroud)

这是我们项目的结构:

/opt/java/spring/boot/fat/jar/project/chorke?mspn?server/
    ?? MediSpan.Documents.Monograph.css                   [     1,697 Byte]
    ?? MediSpan.Documents.Monograph.xslt                  [    35,167 Byte]
    ?? bitronix-tx-mgr-log-001                            [ 2,097,173 Byte]
    ?? bitronix-tx-mgr-log-002                            [ 2,097,173 Byte]
    ?? chorke?mspn?server.jar!                            [26,022,610 Byte]
        ?? medispan/                                      [   443,756 Byte]
        ?? META-INF/                                      [    33,702 Byte]
        ?? org/springframework/boot/loader/               [   165,003 Byte]
        ?? com/chorke/                                    [    27,633 Byte]
        ?? application.properties                         [       501 Byte]
        ?? application.yml                                [     2,234 Byte]
        ?? MediSpan.Foundation.Config.xml                 [    14,939 Byte]
        ?? MediSpan.Foundation.Text.xml                   [     9,003 Byte]
        ?? log4j.xml …
Run Code Online (Sandbox Code Playgroud)

java spring spring-mvc apache-camel spring-boot

6
推荐指数
1
解决办法
6302
查看次数

邮件签名和加密

我想签名并加密我的邮件.

我目前的骆驼版是2.13.0.

有没有我可以用于此目的的骆驼功能?

正文是纯文本,因此不能使用XMLDSig左右.

预期结果应该是包含以下标题的邮件:

  • 内容类型:application/pkcs7-mime; NAME = "smime.p7m"; SMIME型=包膜数据
  • 内容传输编码:base64

email encryption apache-camel

6
推荐指数
1
解决办法
1238
查看次数

用途和差异黑白Apache骆驼Kafka消费者URI选项消费者流vs消费者数

Apache Camel Kafka Consumer提供了称为“ consumerStreams”和“ consumersCount”的URI选项。

需要了解差异和使用场景,以及如何适应多分区Kafka主题消息的使用

apache-camel apache-kafka

6
推荐指数
2
解决办法
850
查看次数

自动装配构造函数时没有路线的骆驼

我使用带模块的弹簧靴.我有一个包含多个子模块的父项目.

当我使用Contructor Autowiring配置路由时,Camel Routes无法启动.

我得到Total 0 routes, of which 0 are started像这样的启动构造函数.

private final ScanProcessor scanProcessor;
private final ScheduleProcessor scheduleProcessor;
private final TagProcessor tagProcessor;
private final LatestScanProcessor latestScanProcessor;
private final RabbitMqService rabbitMqService;

@Autowired
public DashboardRoute(ScanProcessor scanProcessor,
                      ScheduleProcessor scheduleProcessor,
                      TagProcessor tagProcessor,
                      LatestScanProcessor latestScanProcessor,
                      RabbitMqService rabbitMqService){
    this.scanProcessor = scanProcessor;
    this.scheduleProcessor = scheduleProcessor;
    this.tagProcessor = tagProcessor;
    this.latestScanProcessor = latestScanProcessor;
    this.rabbitMqService = rabbitMqService;
}

@Override
public void configure() throws Exception {
           from(CONSUME_SCHEDULE_ROUTE)
            .routeId("consume-schedule")
            .process(scheduleProcessor);  // no strings
}
Run Code Online (Sandbox Code Playgroud)

当我不对任何豆子进行自动装配并对这样的路线进行处理时,整个过程都有效.

 from(CONSUME_SCHEDULE_ROUTE)
   .routeId("consume-schedule")
   .process("scheduleProcessor") …
Run Code Online (Sandbox Code Playgroud)

java spring apache-camel

6
推荐指数
1
解决办法
375
查看次数

从Apache Camel中的特定Offset开始阅读Kafka主题

我阅读了Camel Kafka的所有文档,我读到的唯一方法是来自git和指定的路由构建器

    public void configure() throws Exception {
                    from("kafka:" + TOPIC
                                 + "?groupId=A"
                                 + "&autoOffsetReset=earliest"             // Ask to start from the beginning if we have unknown offset
                                 + "&consumersCount=2"                     // We have 2 partitions, we want 1 consumer per partition
                                 + "&offsetRepository=#offset")            // Keep the offset in our repository
                            .to("mock:result");

}
Run Code Online (Sandbox Code Playgroud)

但是对于客户的订单,我需要使用Spring,所以我的kafka端点就是这样

<!--DEFINE KAFKA'S TOPCIS AS ENDPOINT-->
        <endpoint id="tagBlink" uri="kafka:10.0.0.165:9092">
            <property key="topic" value="tagBlink"/>
            <property key="brokers" value="10.0.0.165:9092"/>
            <property key="offsetRepository" value="100"/>
        </endpoint>
Run Code Online (Sandbox Code Playgroud)

但得到一个例外

无法为属性找到合适的setter:offsetRepository,因为没有相同类型的setter方法:java.lang.String也不能进行类型转换:没有类型转换器可用于从类型:java.lang.String转换为所需类型:org.apache.camel.spi.StateRepository,值为100

这是我的当前配置吗?如何从特定偏移恢复??

java apache-camel apache-kafka

6
推荐指数
1
解决办法
909
查看次数