Spring Transaction Management + Active MQ + Datasource - spring

Here is the flow:
Begin Transaction.
Message put into the queue but not ready to be dequeue. (Right now I don't know how to achieve it)
(i)End Transaction - Successful: Message will be available to be dequeue.
(ii) Rollback: Message will be removed from queue.
Message successfully de-queue by the Listener.
I can configure Spring Transaction Manager for hibernate entities. Same way I can Active MQ available for JMSTransactionManager. But the big question is How would JMSTransactionManager will know the state of HibernateTransactionManager? How would these two interact?
Note: I am using Tomcat managed datasources for Hibernate entities. Apache Camel support is also available in project.

You need an XA-enabled transaction manager, and Spring doesn't come with any. So either deploy your app in a Java EE application server, or embed a stand-alone transaction manager like Bitronix.

Related

Send a message to wildfly JMS message queue using spring boot

My questions is related to an older post.
I am trying to publish a message to a Wildfly JMS queue. Right now the queues and the app run on the same JBoss container. I am trying to create a new Spring Boot app that can publish messages to the existing queues from another container. Since Wildfly is old I am not finding much help online.
All JMS clients (including Spring JMS) need basic things like JNDI context properties, admin object names, etc. You can refer to the Wildfly Hello World JMS Quickstart for these details and then plug them in to your Spring Boot application. The actual names of the admin objects (i.e. connection factory, queue, etc.) will, of course, vary based on your particular configuration.

Standalone spring app XA transactions with IBM MQ and Oracle as resources

I am in the process of developing a stand alone Apache camel application (not running on a J2EE container).
This apps needs to be capable of routing messages from an IBM MQ queue manager to an Oracle database in a distributed transaction.
My google searches pretty much took me to a few places but none of those were able to give me some good clues about how to put everything together.
This link below was the closest to what I need but unfortunately it is not cler enough to put me on the right path.
IBM MQManager as XA Transaction Manager with Spring-jms and Spring-tx
Thank you in advance for your inputs.
You will need to use a JTA TransactionManager, but since not being in a j2ee container i would sugest to use Atomikos.
https://github.com/camelinaction/camelinaction/tree/master/chapter9/xa
My route which is working with IBM MQ -> Oracle Database, in an J2EE yes but still should be working with Atomikos setup. I would say this isn't the proper way to to it, but it's the only way I managed to get it working - working well enough for my use case.
from(inQueue)
.transacted()
.setHeader("storeData", constant(false))
.to("direct:a")
.choice().when(header("storeData").isEqualTo(false)) // if this is true the database calls are 'successful'
.log("Sending message to errorQueue")
.to(errorQueue)
;
StoreDataBean storeDataBean = new StoreDataBean();
from("direct:a")
.onException(Exception.class).handled(false).log("Rollbacking database changes").markRollbackOnlyLast().end()
.transacted("PROPAGATION_REQUIRES_NEW")
.bean(storeDataBean) //storeData sets the header storeData to true if no SQLException or other exceptions are thrown
.end()
;
The commit are handled by the transaction manager, so if I actually get an error with the database commit, it should rollback the message.
Next problem that I have had with rollbacking messages is that I can't set the deadLetterQueue, as you can with ActiveMQ. So it rolls back to the incoming queue. Therefore I actually handle the database transaction as I do, it is in a new transaction, which is rollbacked in case of a normal SQLException when calling the database.
I wished this worked:
from(inQueue)
.onException(Exception.class).to(errorQueue).markRollbackOnly().end()
.bean(storeDataBean)
.end()
I have posted about this in the community forums but no answers at all.

Does Spring XD re-process the same message when one of it's container goes down while processing the message?

Application Data Flow:
JSon Messages--> Active MQ --> Spring XD-- Business Login(Transform JSon to Java Object)--> Save Data to Target DB--> DB.
Question:
Sprin-Xd is running in cluster mode, configured with Radis.
Spring XD picks up the message from the Active message queue(AMQ). So message is no longer in AMQ. Now while one of the containers where this message is being processed with some business logic suddenly goes down. In this scenarios-
Will Spring-XD framework automatically re-process that particular message ? what's mechanism behind that?
Thanks,
Abhi
Not with a Redis transport; Redis has no infrastructure to support such a requirement ("transactional" reads). You would need to use a rabbit or kafka transport.
EDIT:
See Application Configuration (scroll down to RabbitMQ) and Message Bus Configuration.
Specifically, the default ackMode is AUTO which means messages are acknowledged on success.

Spring 2.5.6 with Java Transaction rollback on Database outage

I have got an application which has got non transactional code.
Currently in Java 6 and Spring 2.5.6 ( use ibatis-sqlmap-2.3.0).
The requirement is that while processing an enterprise service bean messageĀ if a database outage happens the transaction should be rolled back and puts the message back into queue.
What changes should I make can you please give me a pointer ?
You can use Two Face Commits to integrate Spring with JMS and a database. We use Atomikos as a transaction manager. Have a look at http://www.atomikos.com/Documentation/TwoPhaseCommitWithTomcatSpringJMSAndJDBC .
You should consider upgrading your Spring Project. Spring 3.2.x is the lowest supported version.

Multiple (Tomcat + ActiveMQ + Mysql) Transaction Management

We have Multiple Tomcat providing web services for our internal product.
Tomcat, Active MQ servers are different
Web services call sequence
Tomcat Receive request
Start DB Transaction (Spring Transaction)
Execute some business logic
Generate certain events & push in queue (Active MQ)
Start JMS Transaction
Push in queue
Commit JMS
Execute other business logic
(other business logic may generate another event for JMS)
Commit DB.
So what i want is to start Global Transaction which should take care of committing respective transaction in sequence.
JMS should only get commit if DB is getting commit.
Is it possible with JTA??????
Your suggestions are welcome.
Yes. See these posts:
Configuring Spring and JTA without full Java EE
Configuring ActiveMQ transactions in Spring

Resources