-
1. Re: Using Narayana to make two RESTful services transactional
mmusgrov Jan 2, 2018 5:15 AM (in response to txuser)We have a REST API to our narayana transaction manager, it is called REST-AT/RTS. To use it with a JTA resources (such as a database or JMS queue) you also need to use the RTS JTA bridge. Take a look at the jta-service quickstart to see how you can use it to solve your use case.
-
2. Re: Using Narayana to make two RESTful services transactional
txuser Jan 2, 2018 10:22 AM (in response to mmusgrov)Thanks. For JPA, I am using spring transactions and it is working fine with local transactions inside each web service. Can I use Spring transactions together with Narayana?
-
3. Re: Using Narayana to make two RESTful services transactional
mmusgrov Jan 2, 2018 12:25 PM (in response to txuser)So you have configured Spring to use the narayana transaction manager (see the spring JTA quickstart). If so I think you can still use the RTS JTA bridging feature. If you follow the instructions for the quickstart you will see that you need to enable the optional RTS subsystem (the parent quickstart contains the instructions). Look at your wildfly distribution, there will be a example config file called ${JBOSS_HOME}/docs/examples/configs/standalone-rts.xml which automatically installs bridging support. This subsystem installs the REST-AT coordinator (the component that manages transactions propagated between JAX-RS services), the REST-AT JTA bridge (the component that enlists JTA resources with the REST-AT coordinator), and the JAX-RS filter responsible for receiving the transaction context on JAX-RS invocations. When the client commits the REST-AT transaction any JTA resources (such as JPA or JMS) that have been updated during any transactional JAX-RS resource invocation (ie resources annotated with the standard @TransactionAttribute annotation) will be told to prepare and commit. As is usual with "distributed XA transactions" if any resource cannot prepare then the whole transaction will abort.
-
4. Re: Using Narayana to make two RESTful services transactional
zhfeng Jan 3, 2018 3:21 AM (in response to txuser)I think if all of the services are deployed on the wildfly, it could be fine to use the RTS and the bridging. But if you run with the spring or spring-boot standalone application, it would be a problem with the transaction propagated.
-
5. Re: Using Narayana to make two RESTful services transactional
txuser Jan 3, 2018 10:33 AM (in response to zhfeng)Thanks. I have both REST services deployed to wildfly. I am going through the examples and trying to do a POC for my scenario.
-
6. Re: Using Narayana to make two RESTful services transactional
txuser Jan 4, 2018 11:17 AM (in response to txuser)Hi, The oracle data sources which we user are non XA. Both of our web services are pointing to the same database. Do you think we need XA datasources. Is there anyway we can make non XA datasource to be transaction aware?
-
7. Re: Using Narayana to make two RESTful services transactional
mmusgrov Jan 8, 2018 4:40 AM (in response to txuser)If the two services need to coordinate their work on the database then you need to ensure that they are XA by setting the jta attribute on the datasource to true:
<datasource jta="true" jndi-name=oracle ...etc
Even though both services are running in the same JVM and doing work on the same datasource I am not aware of any optimisation that enables the work done as if it were a local transaction. Note that if you ever did decide to separate out the two services into separate JVMs then you would definitely need to set jta="true" on the datasources.
-
8. Re: Using Narayana to make two RESTful services transactional
txuser Jan 8, 2018 10:28 AM (in response to mmusgrov)Thanks Michael. I already set jta="true" in my non-xa datasource. I was able to get the one rest web service transactional with this setting. When I test, I looked at the sysouts ( which are inside DummyXAResource.java) and I noticed, in the case of rollback, it will not go to prepare(Xid xid) method. I will directly go inside rollback(Xid xid) method and since the file not exist it throws XAException. Is this the expected behavior?. My transaction got rollback though.
I deployed the other web service (Service2) to the same wildfly and did the same setting. I made a client of Service2 and invoked from Service1. But transactions are not rolling back.
Do you think I have some configuration issue. Or this could be because I am not using XA datasource?
I tried with the h2 XADatasource example you had in the project and I was not able to deploy the web service to wildfly. It says, dynamic class cannot be loaded.
-
9. Re: Using Narayana to make two RESTful services transactional
mmusgrov Jan 10, 2018 10:16 AM (in response to txuser)Have you marked the JAX_RS resource method with the @TransactionAttribute annotation. Did you manage to run the jta-service quickstart quickstart? Once you have seen that working you could then try migrating your own app to use the same techniques that it uses.
-
10. Re: Using Narayana to make two RESTful services transactional
txuser Jan 10, 2018 10:19 AM (in response to mmusgrov)I marked as @Transactional. I thought @TransactionAttribute is for ejb. I will modify to add @TransactionAttribute and will update the forum.
-
11. Re: Using Narayana to make two RESTful services transactional
txuser Jan 10, 2018 10:45 AM (in response to txuser)I added @TransactionAttribute and when I try to deploy to wildfly I get "bean type class org.jboss.narayana.rest.bridge.inbound.InboundBridgeFilter is not proxyable because it is final". Below is the dependency I have.
<dependency>
<groupId>org.jboss.narayana.rts</groupId>
<artifactId>restat-bridge</artifactId>
<version>5.7.1.Final</version>
</dependency>
-
12. Re: Using Narayana to make two RESTful services transactional
mmusgrov Jan 10, 2018 11:21 AM (in response to txuser)Are you running with the wildfly configuration that installs the org.wildfly.extension.rts module (the appropriate config file is docs/examples/configs/standalone-rts.xml).
Did you manage to successfully run the jta-service quickstart quickstart?
-
13. Re: Using Narayana to make two RESTful services transactional
mmusgrov Feb 19, 2018 6:54 AM (in response to txuser)Did you make any progress. The example quickstart ( jta-service quickstart) runs regularly in our CI so if you are still having trouble I would go back to getting that example working and then see what you are doing differently.
-
14. Re: Using Narayana to make two RESTful services transactional
txuser Aug 24, 2018 3:14 PM (in response to mmusgrov)After few months, transaction between 2 rest web services became a priority in my company.
I started with spring JTA quickstart. I modified the project little bit to have two inserts and made second insert fail. So I expected the first insert to be rolled back. the The standalone app with my changes working fine. Then I made it a web app.Apart from the configuration already in the project, I added web.xml and made the packaging as "war". I started the wildfly 10.0 server with standalone-rts.xml.
After I execute the app, I did not see the roll back. Then I changed @Transactional to be @TransactionAttribute. When I try to deploy to server I get "bean type class org.jboss.narayana.rest.bridge.inbound.InboundBridgeFilter is not proxyable because it is final". I do see this class as final in source code.
Please let me know whether I am missing some configuration?
Thanks