You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Shane MacPhillamy <rc...@gmail.com> on 2015/01/27 04:12:03 UTC
Starting to use AWS-SNS Camel component in Spring
I’m pretty new to Spring configuration and Camel. I’ve started with an example from the Camel tarball and modified it to use the “awd-sns” URI. Specifying all parameters on the the URI I can successfully create and post to an SNS topic.
I would like to store the AWS credentials and endpoint in the ApplicationContextRegistry at run-time and reference the configuration via amazonSNSClient# in the “aws-sns” URI as described here http://camel.apache.org/aws-sns.html <http://camel.apache.org/aws-sns.html>. The provided example:
AWSCredentials awsCredentials = new BasicAWSCredentials("myAccessKey", "mySecretKey");
ClientConfiguration clientConfiguration = new ClientConfiguration();
clientConfiguration.setProxyHost("http://myProxyHost");
clientConfiguration.setProxyPort(8080);
AmazonSNS client = new AmazonSNSClient(awsCredentials, clientConfiguration);
registry.bind("client", client);
Uses the bind method to store the client details in the registry, from what I can work out the bind method is only applicable JndiRegistry not ApplicationContextRegistry.
My spring/camel-context.xml file is pretty basic and looks like this:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!-- first, define your individual @Configuration classes as beans -->
<bean class="org.apache.camel.example.spring.javaconfig.MyRouteConfig"/>
<!-- be sure the configure class to be processed -->
<context:annotation-config/>
</beans>
Where could I find pointers to the pieces needed to configure Spring so that I can create and modify the clientConfiguration at run-time?
Thanks.
Cheers, Shane
Re: Starting to use AWS-SNS Camel component in Spring
Posted by Claus Ibsen <cl...@gmail.com>.
At runtime you can always use java code to configure and add / remove
/ modify routes in Camel etc.
There is api on CamelContext to work with that. And routes can be
defined in java classes that extend RouteBuilder. As it is just java
code you can do whatever you want to configure.
Though there is runtime containers such as karaf/smx/fuse that can
redeploy applications based on configuration changes etc. So you can
externalize the configuration settings using property placeholders and
configure these external configurations in .cfg or .properties files,
and/or adjust them as well using JMX or OSGi Config Admin.
Or if you follow the container / docker world, then you can build new
images and upgrade by running the new images instead of the old.
On Tue, Jan 27, 2015 at 8:46 AM, Shane MacPhillamy <rc...@gmail.com> wrote:
> Thank you for your reply Claus. As I said in my post I'm quite new to Spring and Camel and yes there are a lot of pages on the Internet about Spring, all quite a opaque to a new comer.
>
> I want to be able to configure the amazonSNSClient at run time, if I follow your example I would be configuring the client at packaging time, which isn't what I want to do.
>
> It would be helpful, not only to me, but I'm sure to others, to offer a snippet that gave some indication of the key camelContext pieces that would need to be set to create the client and set the AWS credentials.
>
> Cheers, Shane
>
>
>> On 27 Jan 2015, at 6:04 pm, Claus Ibsen <cl...@gmail.com> wrote:
>>
>> Hi
>>
>> You can define beans in spring xml file, where you can configure the
>> client just as the example does in java code.
>>
>> <bean id="someName" class="com.foo.SomeClass">
>> <property name="proxyHost" value="..."/>
>> ..
>> </bean>
>>
>> And you can refer to other beans. Its standard spring xml syntax, so
>> you can find plenty of documentation on the internet
>>
>>> On Tue, Jan 27, 2015 at 4:12 AM, Shane MacPhillamy <rc...@gmail.com> wrote:
>>> I’m pretty new to Spring configuration and Camel. I’ve started with an example from the Camel tarball and modified it to use the “awd-sns” URI. Specifying all parameters on the the URI I can successfully create and post to an SNS topic.
>>>
>>> I would like to store the AWS credentials and endpoint in the ApplicationContextRegistry at run-time and reference the configuration via amazonSNSClient# in the “aws-sns” URI as described here http://camel.apache.org/aws-sns.html <http://camel.apache.org/aws-sns.html>. The provided example:
>>>
>>> AWSCredentials awsCredentials = new BasicAWSCredentials("myAccessKey", "mySecretKey");
>>> ClientConfiguration clientConfiguration = new ClientConfiguration();
>>> clientConfiguration.setProxyHost("http://myProxyHost");
>>> clientConfiguration.setProxyPort(8080);
>>> AmazonSNS client = new AmazonSNSClient(awsCredentials, clientConfiguration);
>>>
>>> registry.bind("client", client);
>>>
>>> Uses the bind method to store the client details in the registry, from what I can work out the bind method is only applicable JndiRegistry not ApplicationContextRegistry.
>>>
>>> My spring/camel-context.xml file is pretty basic and looks like this:
>>>
>>> <beans xmlns="http://www.springframework.org/schema/beans"
>>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>> xmlns:context="http://www.springframework.org/schema/context"
>>> xsi:schemaLocation="
>>> http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
>>> http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
>>>
>>> <!-- first, define your individual @Configuration classes as beans -->
>>> <bean class="org.apache.camel.example.spring.javaconfig.MyRouteConfig"/>
>>>
>>> <!-- be sure the configure class to be processed -->
>>> <context:annotation-config/>
>>>
>>> </beans>
>>>
>>> Where could I find pointers to the pieces needed to configure Spring so that I can create and modify the clientConfiguration at run-time?
>>>
>>> Thanks.
>>>
>>> Cheers, Shane
>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> Red Hat, Inc.
>> Email: cibsen@redhat.com
>> Twitter: davsclaus
>> Blog: http://davsclaus.com
>> Author of Camel in Action: http://www.manning.com/ibsen
>> hawtio: http://hawt.io/
>> fabric8: http://fabric8.io/
--
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/
Re: Starting to use AWS-SNS Camel component in Spring
Posted by Shane MacPhillamy <rc...@gmail.com>.
Thank you for your reply Claus. As I said in my post I'm quite new to Spring and Camel and yes there are a lot of pages on the Internet about Spring, all quite a opaque to a new comer.
I want to be able to configure the amazonSNSClient at run time, if I follow your example I would be configuring the client at packaging time, which isn't what I want to do.
It would be helpful, not only to me, but I'm sure to others, to offer a snippet that gave some indication of the key camelContext pieces that would need to be set to create the client and set the AWS credentials.
Cheers, Shane
> On 27 Jan 2015, at 6:04 pm, Claus Ibsen <cl...@gmail.com> wrote:
>
> Hi
>
> You can define beans in spring xml file, where you can configure the
> client just as the example does in java code.
>
> <bean id="someName" class="com.foo.SomeClass">
> <property name="proxyHost" value="..."/>
> ..
> </bean>
>
> And you can refer to other beans. Its standard spring xml syntax, so
> you can find plenty of documentation on the internet
>
>> On Tue, Jan 27, 2015 at 4:12 AM, Shane MacPhillamy <rc...@gmail.com> wrote:
>> I’m pretty new to Spring configuration and Camel. I’ve started with an example from the Camel tarball and modified it to use the “awd-sns” URI. Specifying all parameters on the the URI I can successfully create and post to an SNS topic.
>>
>> I would like to store the AWS credentials and endpoint in the ApplicationContextRegistry at run-time and reference the configuration via amazonSNSClient# in the “aws-sns” URI as described here http://camel.apache.org/aws-sns.html <http://camel.apache.org/aws-sns.html>. The provided example:
>>
>> AWSCredentials awsCredentials = new BasicAWSCredentials("myAccessKey", "mySecretKey");
>> ClientConfiguration clientConfiguration = new ClientConfiguration();
>> clientConfiguration.setProxyHost("http://myProxyHost");
>> clientConfiguration.setProxyPort(8080);
>> AmazonSNS client = new AmazonSNSClient(awsCredentials, clientConfiguration);
>>
>> registry.bind("client", client);
>>
>> Uses the bind method to store the client details in the registry, from what I can work out the bind method is only applicable JndiRegistry not ApplicationContextRegistry.
>>
>> My spring/camel-context.xml file is pretty basic and looks like this:
>>
>> <beans xmlns="http://www.springframework.org/schema/beans"
>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>> xmlns:context="http://www.springframework.org/schema/context"
>> xsi:schemaLocation="
>> http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
>> http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
>>
>> <!-- first, define your individual @Configuration classes as beans -->
>> <bean class="org.apache.camel.example.spring.javaconfig.MyRouteConfig"/>
>>
>> <!-- be sure the configure class to be processed -->
>> <context:annotation-config/>
>>
>> </beans>
>>
>> Where could I find pointers to the pieces needed to configure Spring so that I can create and modify the clientConfiguration at run-time?
>>
>> Thanks.
>>
>> Cheers, Shane
>
>
>
> --
> Claus Ibsen
> -----------------
> Red Hat, Inc.
> Email: cibsen@redhat.com
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen
> hawtio: http://hawt.io/
> fabric8: http://fabric8.io/
Re: Starting to use AWS-SNS Camel component in Spring
Posted by Claus Ibsen <cl...@gmail.com>.
Hi
You can define beans in spring xml file, where you can configure the
client just as the example does in java code.
<bean id="someName" class="com.foo.SomeClass">
<property name="proxyHost" value="..."/>
..
</bean>
And you can refer to other beans. Its standard spring xml syntax, so
you can find plenty of documentation on the internet
On Tue, Jan 27, 2015 at 4:12 AM, Shane MacPhillamy <rc...@gmail.com> wrote:
> I’m pretty new to Spring configuration and Camel. I’ve started with an example from the Camel tarball and modified it to use the “awd-sns” URI. Specifying all parameters on the the URI I can successfully create and post to an SNS topic.
>
> I would like to store the AWS credentials and endpoint in the ApplicationContextRegistry at run-time and reference the configuration via amazonSNSClient# in the “aws-sns” URI as described here http://camel.apache.org/aws-sns.html <http://camel.apache.org/aws-sns.html>. The provided example:
>
> AWSCredentials awsCredentials = new BasicAWSCredentials("myAccessKey", "mySecretKey");
> ClientConfiguration clientConfiguration = new ClientConfiguration();
> clientConfiguration.setProxyHost("http://myProxyHost");
> clientConfiguration.setProxyPort(8080);
> AmazonSNS client = new AmazonSNSClient(awsCredentials, clientConfiguration);
>
> registry.bind("client", client);
>
> Uses the bind method to store the client details in the registry, from what I can work out the bind method is only applicable JndiRegistry not ApplicationContextRegistry.
>
> My spring/camel-context.xml file is pretty basic and looks like this:
>
> <beans xmlns="http://www.springframework.org/schema/beans"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:context="http://www.springframework.org/schema/context"
> xsi:schemaLocation="
> http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
> http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
>
> <!-- first, define your individual @Configuration classes as beans -->
> <bean class="org.apache.camel.example.spring.javaconfig.MyRouteConfig"/>
>
> <!-- be sure the configure class to be processed -->
> <context:annotation-config/>
>
> </beans>
>
> Where could I find pointers to the pieces needed to configure Spring so that I can create and modify the clientConfiguration at run-time?
>
> Thanks.
>
> Cheers, Shane
>
--
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/