Re: Math Operation in Loop

2018-04-22 Thread Zoran Regvart
Hi Weiqiang,
the simple language can not do what you want, you can look at the
supported operations in the docs[1].

A best practice would be to create a standard Java method to perform
that and use the `method` DSL and set a header value, you can use also
dynamic expressions in Groovy or some other supported expression
language (look at that documentation).

For example:

public class Utilities {
public static int myExpression(final Exchange exchange) {
return exchange.getProperty("CamelLoopIndex", Integer.class) * 10 + 1;
}
}

And in the route DSL:

.loop(10)
  .setHeader("groovyExpressionValue",
GroovyLanguage.groovy("exchange.properties.CamelLoopIndex * 10 + 1"))
  .setHeader("methodExpressionValue", method(Utilities.class,
"myExpression"))
  .log("${header.groovyExpressionValue}")
  .log("${header.methodExpressionValue}")

zoran

[1] 
https://github.com/apache/camel/blob/master/camel-core/src/main/docs/simple-language.adoc

On Fri, Apr 20, 2018 at 11:24 PM, Weiqiang Wang  wrote:
> Hi,
>
> I want to have some math operation in route loop based on the index:
>
> .loop(5)
> .log(String.valueOf(Integer.parseInt("${property.CamelLoopIndex}")*10+1));
>
> But I got error:
> error=For input string: "${property.CamelLoopIndex}"}
>
> If I change it to a constant string, it works. (e.g. "1").
> I also tried use simple without any luck.
> setheader and setbody would cause the same issue when retrieving value
> ${hearder.}
>
> I want to create a variable outside dsl, but not sure how to assign
> variable value in the dsl.
>
> How to do a math calculation based on the loop index.
>
> --
> Weiqiang



-- 
Zoran Regvart


Re: Apache Camel - rabbitmq - ssl ( not working )

2018-04-22 Thread Zoran Regvart
Hi Pranay,
seems that you have a network issue (Connection refused), make sure
that the configuration references the right host/port combination. I
have found that setting `-Djavax.net.debug=all` JVM property is quite
helpful to diagnose such issues.

zoran

On Wed, Apr 11, 2018 at 4:20 AM, Pranay Tonpay  wrote:
> I am trying to use apache camel ( camel-spring-boot - 2.20.2 ) with
> rabbitmq and create routes. It does work fine when iI use un-secured
> RabbitMQ ( no-SSL ), but when iI try to connect to RabbitMQ using SSL, it's
> not connecting to the queue at all. I am using "connectionFactory" option
> given on Apache Camel page. This connectionFactory object has all the
> correct parameters set (useSslProtocol, username, password etc ) Please
> note that the connectionFactory is properly populated, as iI am able to use
> it to connect using the other way (setting it in setConnectionFactory on
> SimpleMessageListenerContainer ). But with Apache Camel iI am facing issues.
>
> java.net.ConnectException: Connection refused (Connection refused)
> at java.net.PlainSocketImpl.socketConnect(Native Method) ~[?:1.8.0_161]
> at
> java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
> ~[?:1.8.0_161]
> at
> java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
> ~[?:1.8.0_161]
> at
> java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
> ~[?:1.8.0_161]
> at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
> ~[?:1.8.0_161]
> at java.net.Socket.connect(Socket.java:589) ~[?:1.8.0_161]
> at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:673)
> ~[?:1.8.0_161]
> at
> com.rabbitmq.client.impl.SocketFrameHandlerFactory.create(SocketFrameHandlerFactory.java:50)
> ~[amqp-client-4.1.0.jar!/:4.1.0]
> at
> com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:918)
> ~[amqp-client-4.1.0.jar!/:4.1.0]
> at
> com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:870)
> ~[amqp-client-4.1.0.jar!/:4.1.0]
> at
> com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:828)
> ~[amqp-client-4.1.0.jar!/:4.1.0]
> at
> com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:996)
> ~[amqp-client-4.1.0.jar!/:4.1.0]
> at
> org.apache.camel.component.rabbitmq.RabbitMQEndpoint.connect(RabbitMQEndpoint.java:248)
> ~[camel-rabbitmq-2.20.2.jar!/:2.20.2]
> at
> org.apache.camel.component.rabbitmq.RabbitMQConsumer.openConnection(RabbitMQConsumer.java:64)
> ~[camel-rabbitmq-2.20.2.jar!/:2.20.2]
> at
> org.apache.camel.component.rabbitmq.RabbitMQConsumer.getConnection(RabbitMQConsumer.java:75)
> ~[camel-rabbitmq-2.20.2.jar!/:2.20.2]
> at
> org.apache.camel.component.rabbitmq.RabbitConsumer.(RabbitConsumer.java:55)
> [camel-rabbitmq-2.20.2.jar!/:2.20.2]
> at
> org.apache.camel.component.rabbitmq.RabbitMQConsumer.createConsumer(RabbitMQConsumer.java:120)
> [camel-rabbitmq-2.20.2.jar!/:2.20.2]



-- 
Zoran Regvart


Re: Math Operation in Loop

2018-04-22 Thread Weiqiang Wang
Thank you Zoran

On Sun, Apr 22, 2018, 5:30 AM Zoran Regvart  wrote:

> Hi Weiqiang,
> the simple language can not do what you want, you can look at the
> supported operations in the docs[1].
>
> A best practice would be to create a standard Java method to perform
> that and use the `method` DSL and set a header value, you can use also
> dynamic expressions in Groovy or some other supported expression
> language (look at that documentation).
>
> For example:
>
> public class Utilities {
> public static int myExpression(final Exchange exchange) {
> return exchange.getProperty("CamelLoopIndex", Integer.class) * 10
> + 1;
> }
> }
>
> And in the route DSL:
>
> .loop(10)
>   .setHeader("groovyExpressionValue",
> GroovyLanguage.groovy("exchange.properties.CamelLoopIndex * 10 + 1"))
>   .setHeader("methodExpressionValue", method(Utilities.class,
> "myExpression"))
>   .log("${header.groovyExpressionValue}")
>   .log("${header.methodExpressionValue}")
>
> zoran
>
> [1]
> https://github.com/apache/camel/blob/master/camel-core/src/main/docs/simple-language.adoc
>
> On Fri, Apr 20, 2018 at 11:24 PM, Weiqiang Wang  wrote:
> > Hi,
> >
> > I want to have some math operation in route loop based on the index:
> >
> > .loop(5)
> >
> .log(String.valueOf(Integer.parseInt("${property.CamelLoopIndex}")*10+1));
> >
> > But I got error:
> > error=For input string: "${property.CamelLoopIndex}"}
> >
> > If I change it to a constant string, it works. (e.g. "1").
> > I also tried use simple without any luck.
> > setheader and setbody would cause the same issue when retrieving value
> > ${hearder.}
> >
> > I want to create a variable outside dsl, but not sure how to assign
> > variable value in the dsl.
> >
> > How to do a math calculation based on the loop index.
> >
> > --
> > Weiqiang
>
>
>
> --
> Zoran Regvart
>