Friday, 15 June 2012

AMQP with transaction manager in RPC model -



AMQP with transaction manager in RPC model -

i using spring-amqp/rabbitmq project rpc. able send , receive message via message broker without problem.

here working code

<bean id="stblistener" class="org.springframework.amqp.remoting.service.a mqpinvokerserviceexporter"> <property name="serviceinterface" value="com.java.stb.service.api.stbservice" /> <property name="service" ref="stbservice" /> <property name="amqptemplate" ref="template" /> </bean> <bean id="stbservice" class="com.java.stb.service.impl.stbserviceimpl" /> <rabbit:connection-factory id="connectionfactory" channel-cache-size="10" /> <rabbit:admin connection-factory="connectionfactory" auto-startup="false" /> <rabbit:template id="template" connection-factory="connectionfactory" channel-transacted="true" /> <rabbit:queue name="${queue}" /> <rabbit:listener-container connection-factory="connectionfactory"> <rabbit:listener ref="stblistener" queue-names="${queue}" /> </rabbit:listener-container>

and added @transactional annotation in producer method get/insert/update info in postgres. having issue message producer. copied producer code below added transaction manager

<bean id="stblistener" class="org.springframework.amqp.remoting.service.a mqpinvokerserviceexporter"> <property name="serviceinterface" value="com.java.stb.service.api.stbservice" /> <property name="service" ref="stbservice" /> <property name="amqptemplate" ref="template" /> </bean> <bean id="rabbittxmanager" class="org.springframework.amqp.rabbit.transaction .rabbittransactionmanager"> <property name="connectionfactory" ref="connectionfactory" /> </bean> <bean id="stbservice" class="com.java.stb.service.impl.stbserviceimpl" /> <rabbit:connection-factory id="connectionfactory" channel-cache-size="10" /> <rabbit:admin connection-factory="connectionfactory" auto-startup="false" /> <rabbit:template id="template" connection-factory="connectionfactory" channel-transacted="true" /> <rabbit:queue name="${queue}" /> <rabbit:listener-container concurrency="20" prefetch="20" transaction-size="10" auto-startup="false" connection-factory="connectionfactory" transaction-manager="rabbittxmanager"> <rabbit:listener ref="stblistener" queue-names="${queue}" /> </rabbit:listener-container>

i getting timeout error

caused by: org.springframework.remoting.remoteproxyfailureexc eption: no reply received - perhaps timeout in template? @ org.springframework.amqp.remoting.client.amqpclien tinterceptor.invoke(amqpclientinterceptor.java:60) @ org.springframework.aop.framework.reflectivemethod invocation.proceed(reflectivemethodinvocation.java :172) @ org.springframework.aop.framework.jdkdynamicaoppro xy.invoke(jdkdynamicaopproxy.java:204) @ com.sun.proxy.$proxy7.isidentityavailableforstb(un known source) @ tv.moonweb.stb.service.api.stbserviceclient.isiden tityavailableforstb(stbserviceclient.java:101) ... 17 more

i set reply-timeout="10000" in consumer side.

please help me solve problem

thank-you in advance

gopy

i suggest turn on debug logging on both sides; if can't figure out problem is, post logs somewhere , can take look.

it's not clear why added rabbit transaction manager on consumer side when said added @transactional on producer side.

if stbserviceimpl talks db, transaction manager should jdbc transaction manager.

if want downstream rabbittemplate participate in inbound session, message listener container needs channel-transacted - otherwise listener runs in non-transactional channel.

spring-transactions spring-amqp

No comments:

Post a Comment