Use ActiveMQ in Travis CI - spring

My build in Travis CI failed after add configuration on Active MQ.
The log of Travis CI shows:
Caused by: javax.jms.JMSException: Could not connect to broker URL: tcp://localhost:61616. Reason: java.net.ConnectException: Connection refused
at org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:36)
at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:360)
at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:305)
at org.apache.activemq.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:245)
at org.springframework.jms.connection.SingleConnectionFactory.doCreateConnection(SingleConnectionFactory.java:365)
at org.springframework.jms.connection.SingleConnectionFactory.initConnection(SingleConnectionFactory.java:305)
at org.springframework.jms.connection.SingleConnectionFactory.getConnection(SingleConnectionFactory.java:283)
at org.springframework.jms.connection.SingleConnectionFactory.createConnection(SingleConnectionFactory.java:224)
at org.springframework.jms.support.JmsAccessor.createConnection(JmsAccessor.java:180)
at org.springframework.jms.listener.AbstractJmsListeningContainer.createSharedConnection(AbstractJmsListeningContainer.java:413)
at org.springframework.jms.listener.AbstractJmsListeningContainer.establishSharedConnection(AbstractJmsListeningContainer.java:381)
at org.springframework.jms.listener.AbstractJmsListeningContainer.doStart(AbstractJmsListeningContainer.java:285)
at org.springframework.jms.listener.SimpleMessageListenerContainer.doStart(SimpleMessageListenerContainer.java:209)
at org.springframework.jms.listener.AbstractJmsListeningContainer.start(AbstractJmsListeningContainer.java:270)
... 44 more
I'm using Spring MVC, here's the configuration for testing:
<beans "Some DTDs here">
<!-- Base Components -->
<context:annotation-config />
<context:component-scan base-package="com.trunkshell.voj" />
<!-- Some other configuration for JDBC and other service -->
<!-- Message Service -->
<bean id="amqConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<constructor-arg index="0" value="tcp://localhost:61616"/>
</bean>
<bean id="connectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
<constructor-arg ref="amqConnectionFactory" />
</bean>
<bean id="defaultDestination" class="org.apache.activemq.command.ActiveMQQueue">
<constructor-arg index="0" value="vojMessageQueue"/>
</bean>
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="connectionFactory" />
<property name="defaultDestination" ref="defaultDestination" />
</bean>
<bean class="org.springframework.jms.listener.SimpleMessageListenerContainer">
<property name="connectionFactory" ref="connectionFactory" />
<property name="destinationName" value="vojMessageQueue" />
<property name="messageListener" ref="messageReceiver" />
</bean>
<bean id="messageSender" class="com.trunkshell.voj.util.MessageSender"></bean>
<bean id="messageReceiver" class="com.trunkshell.voj.util.MessageReceiver"></bean>
</beans>
I also noticed that Travis CI only support RabbitMQ and ZeroMQ.
Here's the reference: link
So what should I do to fix the error in Travis CI?
Or how to skip this problem in Travis CI.

I don't see that you actually start an ActiveMQ broker at port 61616. Either, do that, or preferably use the VM transport during the integration tests. I.e. change tcp://localhost:61616 to vm://localhost?broker.persistent=false
Of course, you have to be able to change that ActiveMQ URL when you deploy to a production environment. Maybe you can use spring property placeholders?

Related

ActiveMQ 5.15.5, Camel ActiveMQ component brokerURL to connect two standalone brokers

I have two standalone broker consuming message from another system.
The client consumer uses Camel to consume messages, below is the part of the configuration where it used camel-activemq component.
I am trying to provide both the host information within the borkerURL but throwing some exception.
using jars of
spring-core 4.2.4,
spring-boot: 1.3.1,
activemq-camel: 5.12.1,
activemq-broker: 5.12.1, etc.
...
<bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="(tcp://host1:61616,tcp://host2:61616)?wireFormat.maxInactivityDuration=500000" />
</bean>
<bean id="jmsPooledConnectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory" init-method="start" destroy-method="stop">
<property name="maxConnections" value="10" />
<property name="connectionFactory" ref="jmsConnectionFactory" />
</bean>
<bean id="jmsConfig" class="org.apache.camel.component.jms.JmsConfiguration">
<property name="connectionFactory" ref="jmsPooledConnectionFactory" />
<property name="concurrentConsumers" value="1" />
<property name="maxConcurrentConsumers" value="1" />
</bean>
<bean id="jms" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="configuration" ref="jmsConfig" />
<property name="transacted" value="true" />
</bean>
...
The process throw exception, when i run the camel main with the context.
:PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'brokerURL' threw exception; nested exception is java.lang.IllegalArgumentException: Invalid broker URI: (tcp://host1:61616,tcp://host2:61616)?wireFormat.maxInactivityDuration=500000
Is there any way to pass in the borker URL of two standalone brokers?
If the brokers are part of a failover system, use the "failover" protocol of the ActiveMQ client.
If the brokers have different queues, create two different commponents with different configurations and broker URLs.
refer to jms1 or jms2 in your route.

javax.naming.NameNotFoundException: java:jboss/jms/exampleApp/SampleQueueIn

We are migrating from JBoss EAP 6.4 to JBoss EAP 7.0. Our earlier JMS configuration is not working with JBoss 7.0 where it is throwing NameNotFoundException for my JMS beans
my jms.xml
<beans profile="jboss">
<bean id="connectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:jboss/jms/exampleApp/ConnectionFactory" />
<property name="resourceRef" value="true" />
</bean>
<bean id="SampleQueueIn" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:jboss/jms/exampleApp/SampleQueueIn" />
<property name="resourceRef" value="true" />
</bean>
</beans>
My messageListener.xml
<beans profile="jboss">
<!-- Abstract MessageListener -->
<bean id="messageListener" abstract="true" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="connectionFactory" />
<property name="transactionManager" ref="transactionManager" />
<property name="sessionTransacted" value="true" />
<!-- Receive timeout determines the duration of JMS session. Increase from default 1sec to 5sec, to lower the traffic to Queue managers -->
<property name="receiveTimeout" value="5000" />
</bean>
</beans>
my proxy-domain componentContext.xml which has listener beans
<beans profile="jboss">
<bean id="jmsContainer" parent="messageListener">
<property name="destination" ref="SampleQueueIn" />
<property name="messageListener" ref="sampleInformationListenerImpl" />
</bean>
</beans>
commands.cli part for adding admin objects for wmq
/subsystem=resource-adapters/resource-adapter=${wmq_deploy_name}:activate
/subsystem=resource-adapters/resource-adapter=${wmq_deploy_name}/admin-objects=SampleQueueIn:add(class-name=com.ibm.mq.connector.outbound.MQQueueProxy,jndi-name=java:jboss/jms/exampleApp/SampleQueueIn)
/subsystem=resource-adapters/resource-adapter=${wmq_deploy_name}/admin-objects=SampleQueueIn/config-properties=baseQueueName/:add(value=${filter_jms_queue_config_SampleQueueIn_basequeuename})
/subsystem=resource-adapters/resource-adapter=${wmq_deploy_name}/admin-objects=SampleQueueIn/config-properties=baseQueueManagerName/:add(value=${filter_jms_queue_config_basequeuemanager})
I can see my admin objects in the JBoss for wmq under sub resources with correct jndi-name also.
I am using IBM wmq v9.1.0.2.
[EDIT]
Once I deploy my WAR file, I am getting the below exception
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'SampleQueueIn' defined in class path resource [jms.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: jms/exampleApp/SampleQueueIn-- service jboss.naming.context.java.jboss.jms.exampleApp.SampleQueueIn
This configuration was working(still working) in jboss eap 6.4.
I have scourged jboss developer sites & stackoverflow sites but no avail till now!
I can see that my
I resolved the error with reload of JBoss server after running the CLI commands. I automated the execution of both jboss cli commands & reload commands to make sure that the JNDI objects lookup is successful.

Spring: JMSTemplate/CachingConnectionFactory deployables unable to start automatically in weblogic

I recently changed some of my application to use the the following:
org.springframework.jndi.JndiTemplate
org.springframework.jms.connection.CachingConnectionFactory
org.springframework.jms.core.JmsTemplate
Everything is working fine and I'm able to deploy my war files and send JMS messages to the queue.
However something peculiar happens when my managed server restarts. The deployables will all go into a fail state which requires me to then manually start them up.
This started happening after the change to use caching connection factory, jndi template and jms template.
My SpringConfig file:
<!-- Service Controller begin -->
<bean id="appUtils" class="com.foo.util.AppUtil" lazy-init="true" />
<bean id="jms_jndiTemplate" class="org.springframework.jndi.JndiTemplate" lazy-init="true">
<property name="environment">
<props>
<prop key="java.naming.factory.initial">#{jmsJndiFactory}</prop>
<prop key="java.naming.provider.url">#{jmsIp}</prop>
</props>
</property>
</bean>
<bean id="jmsUtils" class="com.foo.JmsUtil" >
<property name="template">
<bean class="org.springframework.jms.core.JmsTemplate" lazy-init="true">
<property name="connectionFactory">
<bean class="org.springframework.jms.connection.CachingConnectionFactory" lazy-init="true">
<property name="sessionCacheSize" value="10" />
<property name="targetConnectionFactory">
<bean class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate" ref="jms_jndiTemplate" />
<property name="jndiName" ref="jmsFactory" />
</bean>
</property>
</bean>
</property>
</bean>
</property>
<property name="destination">
<bean class="org.springframework.jndi.JndiObjectFactoryBean" lazy-init="true">
<property name="jndiTemplate" ref="jms_jndiTemplate" />
<property name="jndiName" ref="jmsQueue" />
</bean>
</property>
</bean>
ApplicationContext file:
<bean id="jmsQueue" class="java.lang.String" ><constructor-arg value="${jmsQueue.local}" /></bean>
<bean id="jmsFactory" class="java.lang.String" ><constructor-arg value="${jmsFactory.local}" /></bean>
<bean id="jmsJndiFactory" class="java.lang.String" ><constructor-arg value="${jmsJndiFactory.local}" /></bean>
<bean id="jmsIp" class="java.lang.String" ><constructor-arg value="${jmsIp.local}" /></bean>
applicationProperties file:
jmsQueue.local=jms/Queue
jmsFactory.local=jms/ConnectionFactory
jmsJndiFactory.local=weblogic.jndi.WLInitialContextFactory
jmsIp.local=t3://localhost:7031
Anyone has any idea as to why this might be happening? I'm using Weblogic. Any help would be greatly appreciated.
Thanks!
Edit: Forgot to mention that the error causing the failed state is
javax.naming.NameNotFoundException: Unable to resolve 'jms.Queue'. Resolved 'jms'; remaining name 'Queue'.
This is a JNDI error. The message means "I tried to find jms/Queue in the JNDI context but I only got as far as jms; there is no Queue child below".
Check the resources which you configured for the application in WebSphere.

SSL Java Client for WebSphere MQ

I try to develop a test client (Java web application) for WebSphere MQ via Spring.
I've enabled the SSL security mechanism for the channel, queue manager and connection factory, using the NULL_MD5 cipher spec.
This is my Spring configuration file:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<context:annotation-config/>
<context:property-placeholder location="classpath:jms.properties"/>
<bean id="jmsFactory" class="com.ibm.mq.jms.MQQueueConnectionFactory">
<property name="hostName" value="${queue_hostname}"/>
<property name="queueManager" value="${queue_manager}"/>
<property name="channel" value="${queue_channel}"/>
<property name="port" value="${queue_port}"/>
<property name="transportType" value="1"/>
<property name="SSLCipherSuite" value="SSL_RSA_WITH_NULL_MD5"/>
</bean>
<bean id="sendDestination" class="com.ibm.mq.jms.MQQueue">
<property name="baseQueueName">
<value>queue.inbound</value>
</property>
</bean>
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory">
<bean class="org.springframework.jms.connection.SingleConnectionFactory">
<property name="targetConnectionFactory">
<ref local="jmsFactory" />
</property>
</bean>
</property>
<property name="defaultDestination">
<ref bean="sendDestination" />
</property>
</bean>
<bean id="messageListener" class="com.test.MessageListener" />
<bean id="jmsContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory">
<bean class="org.springframework.jms.connection.SingleConnectionFactory">
<property name="targetConnectionFactory">
<ref local="jmsFactory" />
</property>
</bean>
</property>
<property name="destination" ref="sendDestination" />
<property name="messageListener" ref="messageListener" />
</bean>
</beans>
The problem is when I try to connect to the WebSphere MQ an exception raises:
Caused by: org.springframework.context.ApplicationContextException: Failed to start bean 'jmsContainer'; nested exception is java.lang.AssertionError
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:170)
at org.springframework.context.support.DefaultLifecycleProcessor.access$1(DefaultLifecycleProcessor.java:154)
at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:339)
at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:143)
at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:108)
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:926)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:467)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:103)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:1)
at org.springframework.test.context.support.DelegatingSmartContextLoader.loadContext(DelegatingSmartContextLoader.java:228)
at org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:124)
at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:148)
... 27 more
Caused by: java.lang.AssertionError
at com.ibm.mq.jmqi.internal.CipherSpec.<init>(CipherSpec.java:53)
at com.ibm.mq.jmqi.JmqiUtils.toCipherSuite(JmqiUtils.java:325)
at com.ibm.mq.jmqi.remote.impl.RemoteTCPConnection.parseCipherSpec(RemoteTCPConnection.java:1984)
at com.ibm.mq.jmqi.remote.impl.RemoteTCPConnection.makeSocketSecure(RemoteTCPConnection.java:1838)
at com.ibm.mq.jmqi.remote.impl.RemoteTCPConnection.connnectUsingLocalAddress(RemoteTCPConnection.java:810)
at com.ibm.mq.jmqi.remote.impl.RemoteTCPConnection.protocolConnect(RemoteTCPConnection.java:1130)
at com.ibm.mq.jmqi.remote.impl.RemoteConnection.connect(RemoteConnection.java:710)
at com.ibm.mq.jmqi.remote.impl.RemoteConnectionSpecification.getSessionFromNewConnection(RemoteConnectionSpecification.java:400)
at com.ibm.mq.jmqi.remote.impl.RemoteConnectionSpecification.getSession(RemoteConnectionSpecification.java:299)
at com.ibm.mq.jmqi.remote.impl.RemoteConnectionPool.getSession(RemoteConnectionPool.java:164)
at com.ibm.mq.jmqi.remote.api.RemoteFAP.jmqiConnect(RemoteFAP.java:1595)
at com.ibm.mq.jmqi.remote.api.RemoteFAP.jmqiConnect(RemoteFAP.java:1223)
at com.ibm.mq.ese.jmqi.InterceptedJmqiImpl.jmqiConnect(InterceptedJmqiImpl.java:311)
at com.ibm.mq.ese.jmqi.ESEJMQI.jmqiConnect(ESEJMQI.java:337)
at com.ibm.msg.client.wmq.internal.WMQConnection.<init>(WMQConnection.java:346)
at com.ibm.msg.client.wmq.factories.WMQConnectionFactory.createV7ProviderConnection(WMQConnectionFactory.java:6876)
at com.ibm.msg.client.wmq.factories.WMQConnectionFactory.createProviderConnection(WMQConnectionFactory.java:6254)
at com.ibm.msg.client.jms.admin.JmsConnectionFactoryImpl.createConnection(JmsConnectionFactoryImpl.java:285)
at com.ibm.mq.jms.MQConnectionFactory.createCommonConnection(MQConnectionFactory.java:6189)
at com.ibm.mq.jms.MQQueueConnectionFactory.createQueueConnection(MQQueueConnectionFactory.java:120)
at com.ibm.mq.jms.MQQueueConnectionFactory.createConnection(MQQueueConnectionFactory.java:203)
at org.springframework.jms.connection.SingleConnectionFactory.doCreateConnection(SingleConnectionFactory.java:342)
at org.springframework.jms.connection.SingleConnectionFactory.initConnection(SingleConnectionFactory.java:288)
at org.springframework.jms.connection.SingleConnectionFactory.createConnection(SingleConnectionFactory.java:225)
at org.springframework.jms.support.JmsAccessor.createConnection(JmsAccessor.java:184)
at org.springframework.jms.listener.AbstractJmsListeningContainer.createSharedConnection(AbstractJmsListeningContainer.java:403)
at org.springframework.jms.listener.AbstractJmsListeningContainer.establishSharedConnection(AbstractJmsListeningContainer.java:371)
at org.springframework.jms.listener.DefaultMessageListenerContainer.establishSharedConnection(DefaultMessageListenerContainer.java:750)
at org.springframework.jms.listener.AbstractJmsListeningContainer.doStart(AbstractJmsListeningContainer.java:278)
at org.springframework.jms.listener.AbstractJmsListeningContainer.start(AbstractJmsListeningContainer.java:263)
at org.springframework.jms.listener.DefaultMessageListenerContainer.start(DefaultMessageListenerContainer.java:556)
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:167)
... 38 more
It is strange that even though I set the SSLCipherSuite property it tries to get the cipher suite by the cipher spec...
Can someone please suggest how to fix this?
This bug is acknowledged here: http://www-01.ibm.com/support/docview.wss?uid=swg1IV36662
And marked as fixed in Websphere MQ fix pack 7.1.0.3.
The recommended (but not entirely satisfactory) workaround is to disable assertions in the JRE command line, with either "-disableassertions" or "-da".
Well, after some research it appeared that the problem is in the assertion mechanism. If assertions are disabled everything works fine. It is strange that you can have a completely working code even if assertions fail... And it is rather pity that I can't find a way to set the cipher spec - only the cipher suite setter is provided by the MQQueueConnectionFactory class.
In case of the weblogic server, there is a parameter named 'debugFlag' that is verified in the WLS_HOME/user_projects/domains/local-domain-name/bin/setDomainEnv.cmd (.sh). If you have it set to 'true' the application would fail. Or you can add the following JAVA_OPTION: -da:com.ibm.mq... at the end of the setDomainEnv.cmd (.sh) file. This way you can leave the debug enabled.
Of cource, it is not a preferrable way to fix the problem, but for now it is the only way I could fix it.

EJB 3.0 -> Spring -> JPA (JTA as transaction manager)

I am currently working on a project that includes EJB 3.0 (stateless SB), JPA (Hibernate as the provider), JTA as transaction manager. The app server is JBoss AS 7. Spring is used for integrating EJB and JPA.
All seems to be working fine, except if there is any exception that occurs in the EJB, then the persistence unit is closed by Spring. On the subsequent request, the persistence unit is again created, which becomes time consuming and also should not happen in the ideal situation.
Below are the configuration details
persistence.xml
<persistence-unit name="test" transaction-type="RESOURCE_LOCAL">
<class>com.test.User</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
</properties>
</persistence-unit>
spring-application-context.xml
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
<jee:jndi-lookup id="dataSource" jndi-name="java:/datasources/test" />
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="generateDdl" value="false" />
<property name="database" value="MYSQL" />
<property name="showSql" value="true" />
<property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect"/>
</bean>
</property>
<property name="jpaPropertyMap">
<map>
<entry key="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"></entry>
<entry key="hibernate.current_session_context_class" value="jta" />
<entry key="hibernate.connection.release_mode" value="auto" />
</map>
</property>
<property name="persistenceUnitPostProcessors">
<list>
<bean class="com.transaction.processor.JtaPersistenceUnitPostProcessor">
<property name="jtaMode" value="true"/>
<property name="jtaDataSource" ref="dataSource"/>
</bean>
</list>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="transactionManagerName" value="java:/TransactionManager"></property>
<property name="autodetectUserTransaction" value="false"></property>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
The class JtaPersistenceUnitPostProcessor is responsible for setting the transaction-type as JTA and the datasource to jta-datasource.
Could anyone please provide any help on this.
Thanks in advance.
<bean id="transactionManager"
class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="transactionManagerName" value="java:jboss/TransactionManager" />
<property name="userTransactionName" value="java:comp/UserTransaction" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
you didn't specify any error message . you can add these lines in your configuration file .
I see you use JTA transaction manager and use that only if you use distributed Transaction and use JNDI. JTA tran. manager listens TX happening through connection acquired from JNDI datasource. If you have datasource created in your code and is not a part of Web container but is limited inside app. container in your web server, JTA wont work.
If you want to implement Tx manager with in a single app. context go for JPA transaction manager which is very reliable.

Resources