I'm using Camel blueprint on JBoss Developer studio, which is a new challenge for me.
I've googled and found stuff like this: http://camel.apache.org/activemq.html but what I'm trying to figure out is how you define your activeMQ connection if you're using the blueprint. Everything references and activeMQ bean, but nothing shows how to define it in the blueprint.
You should create an ActiveMQComponent outside the the camel context :
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
<bean id="activemq"
class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="brokerURL"
value="tcp://localhost:61616" />
</bean>
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
...
</camelContext>
</blueprint>
Note that this is described as "spring XML configuration" in http://camel.apache.org/activemq.html. The blueprint XML schema is mostly the same as the one for Spring (you can list main differences at http://camel.apache.org/using-osgi-blueprint-with-camel.html), so in most case you can use what is described as "spring xml" in blueprint.
Related
We are implementing XA transaction between MQ and database and trying to create a connection factory as a service in karaf as per the below link.
https://access.redhat.com/documentation/fr-fr/red_hat_fuse/7.2/html/apache_karaf_transaction_guide/using-jms-connection-factories#manual-deployment-connection-factories
The MQ we are using is IBM and we are connecting to it through camel.
The karaf service is exposed from the same bundle that is going to use it. This is done through blueprint xml file present in the src/main/resources/OSGI-INF/blueprint folder.
When we use (through JNDI) the connection factory exposed as a service for setting the connection factory to be used by the JmsComponent of camel, we are able to get message from the queue but not able to put message into the queue. There is no error when the put operation fails and hence, the database gets updated with success. This happens specifically when using JmsPoolXAConnectionFactory as the pool connection factory. If we change it to JmsPoolConnectionFactory, the put operation works and the message is added to the queue.
Below are the sample routes for get and put to queue.
GET:
from("mq:queue:{{queueName}}")
.process(new CustomProcessor1())
.to("direct:call-sp")
.end();
from("direct:call-sp")
.to("sql-stored:call-sp")
.end();
PUT:
from("vm:send")
.process(new CustomProcessor2())
.to("mq:queue:{{queueName}}")
.to("sql-stored:update-sp")
.to("vm:nextroute")
.end();
Camel JmsComponent Configuration in camel-context.xml:
<reference id="ptm" interface="org.springframework.transaction.PlatformTransactionManager" />
<reference id="connectionFactory" interface="javax.jms.ConnectionFactory" filter="(osgi.jndi.service.name=jms/mq)" availability="optional" />
<bean id="jmsConfig" class="org.apache.camel.component.jms.JmsConfiguration">
<property name="transacted" value="false" />
<property name="connectionFactory" ref="connectionFactory" />
<property name="transactionManager" ref="ptm" />
</bean>
<bean id="mq" class="org.apache.camel.component.jms.JmsComponent">
<property name="configuration" ref="jmsConfig" />
<property name="destinationResolver" ref="customDestinationResolver" />
</bean>
<bean id="customDestinationResolver" class="com.example.CustomDestinationResolver">
</bean>
Is there any put related specific configuration that we are missing?
To coordinate XA transactions, you need a transaction manager which implements the Java Transaction API (JTA).
Therefore, I think you need to use a JtaTransactionManager rather than a org.springframework.transaction.PlatformTransactionManager.
Check this out:
https://tomd.xyz/camel-xa-transactions-checklist/
I'm using camel. This is (an extract of) my blueprint:
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
<cm:property-placeholder id="placeholder" persistent-id="com.adelco.articulos" />
<!-- Configures the Inbound and Outbound SAP Connections -->
<bean id="sap-configuration" class="org.fusesource.camel.component.sap.SapConnectionConfiguration">
.
.
</bean>
<!--A lot of things here, let's omit them-->
<!-- Route beans-->
<bean id="rutaSTEPEntrada" class="com.adelco.articulos.RutaSTEPEntrada"/>
<bean id="rutaSTEPSap" class="com.adelco.articulos.RutaSTEPSap"/>
<camelContext id="camel-articulos" xmlns="http://camel.apache.org/schema/blueprint">
<routeBuilder ref="rutaSTEPEntrada"/>
<routeBuilder ref="rutaSTEPSap"/>
</camelContext>
</blueprint>
I want "disable" the bean "sap-configuration" but without using XML comments. Something like this:
<bean id="sap-configuration" enabled=${ENABLED} class="org.fusesource.camel.component.sap.SapConnectionConfiguration">
.
.
</bean>
I can define the camel routes I want to activate using "autoStartup" and property placeholders "autoStartup=${ENABLED}" but I can't find how to do this with the bean.
This is not possible. Its how OSGi blueprint works. If you define a <bean> then its in use.
I've referred to the JMS page of the Camel documentation and many related SO questions such as this one, but I'm unable to find a comprehensive list on the implementation.
I'm using Spring XML along with Camel and Weblogic for the server. I've made a test queue with the following names:
Server: TestJMSServer, Module: TestJMSModule, Queue: TestJMSQueue, CF: TestConnectionFactory.
According to the Camel documentation, my route should look something like this:
<camel:route id="test">
<camel:from uri="jms:TestJMSQueue" />
<camel:to uri="file:/Users/...." />
</camel:route>
This gives me an error saying "connectionFactory must be specified". So exactly what else do I need to add to my applicationContext.xml in order to listen to this queue?
You need to tell Camel's jms-component which JMS connection factory to use. Most likely you'll get that from jndi if you're using WebLogic.
In the example below i am looking up the connection factory using spring's jee:jndi-lookup (i believe that might even be a name you can use in WebLogic). The looked up factory is then made available as a spring bean with id myConnectionFactory.
This connection factory bean is then used for the connectionFactory property for camel's JmsComponent. Notice the id attribute: jms. This defines the camel endpoint uri scheme to be used in your routes.
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jee="http://www.springframework.org/schema/jee"
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">
<jee:jndi-lookup id="myConnectionFactory" jndi-name="jms/connectionFactory"/>
<route id="test" xmlns="http://camel.apache.org/schema/spring">
<from uri="jms:TestJMSQueue"/>
<to uri="file:/Users/...."/>
</route>
<bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
<property name="connectionFactory" ref="myConnectionFactory"/>
<!-- more configuration required based on your requirements -->
</bean>
<!--
example uses invm amq broker:
<bean id="anothercnf" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="vm://mybroker"/>
</bean>
-->
</beans>
Important Note: You will need to tune this further (setup transactions, setup concurrent consumers, possible configure a spring jms connection pool)
I found this documentation that documents how to use an ExceptionMapper. But it doesn't provide any information on how to tell the webapp that it should use it. How do I configure that?
You can do this in your Spring configuration file like this:
<jaxrs:server id="foo" address="/v2">
<jaxrs:providers>
<bean class="com.MyExceptionMapper"/>
</jaxrs:providers>
</jaxrs:server>
I am having xml. (Ehcache.xml)
I want to inject into it property from property file(on the classpath).
However since this xml is not a Spring managed bean I am not able to do so.
Any recommendations how to overcome this?
the xml:
...
properties="peerDiscovery=manual,rmiUrls=//**${other.node.hostname}**:41001/org.jasig.cas.ticket.ServiceTicket|//**${other.node.hostname}**:41001/org.jasig.cas.ticket.TicketGrantingTicket"
propertySeparator="," />
<cacheManagerPeerListenerFactory
class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
properties="port=41001,socketTimeoutMillis=5000" />
</ehcache>
I want to inject ${other.node.hostname} from another properties file.
but I get this on runtime:
Caused by: java.net.URISyntaxException: Illegal character in authority at index 2: //${other.node.hostname}:41001/org.jasig.cas.ticket.TicketGrantingTicket
thanks,
ray.
in the ehcache.xml it won't work because it's not spring configuration. But if you define the equivalent configuration in spring instead of the ehcache file it should work:
<context:property-placeholder location="classpath:config.properties"/>
<bean id="myCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
<property name="cacheManager" ref="cacheManager"/>
<property name="maxElementsInMemory" value="${cache.maxMemoryElements}"/>
</bean>
the best is to use the ehcache.xml file the least possible and configure everything in spring, as most of the options in the file have a spring equivalent.