-
30. Re: Using Narayana to make two RESTful services transactional
tomjenkinson Sep 6, 2018 3:25 PM (in response to tomjenkinson)OK, I found that was in our code already
So I have this: Comparing jbosstm:master...tomjenkinson:springExampleinWFLY · jbosstm/quickstart · GitHub
The arquillian test is not working but I think the rest of it is, please give it a try and let us know if it helps
-
31. Re: Using Narayana to make two RESTful services transactional
tomjenkinson Sep 6, 2018 3:28 PM (in response to tomjenkinson)I should say, because the arquillian test is not working: mvn clean install -DskipTests
The arquillian fails because of
Caused by: org.jboss.modules.ModuleNotFoundException: org.jboss.resteasy.resteasy-jaxrs-api
at org.jboss.modules.ModuleLoader.loadModule(ModuleLoader.java:285)
at org.jboss.modules.ModuleLoader.loadModule(ModuleLoader.java:271)
... 141 more
Which I think must be wrong version of Arquillian as the war itself I can access fine:
-
32. Re: Using Narayana to make two RESTful services transactional
txuser Sep 6, 2018 3:33 PM (in response to tomjenkinson)Thank you Tom. I will try and update you soon.
-
33. Re: Using Narayana to make two RESTful services transactional
txuser Sep 6, 2018 4:26 PM (in response to txuser)Hi Tom,
With your changes I deployed the web service to Wildfly10 and I invoked with SOAP UI. I don't have any issues when I try to invoke. But here is what I want to test with this simple test case.
1.I have an insert to example table first.
2. If trigger is 1, I have another insert to example table. Which makes "select count(*) from example" is 2. This is the happy path and working fine.
3. If trigger is anything other than 2, I insert to examples table . Which does not exist. This should throw exception. And it does now
4. In case of an exception in any database calls, I dont need to commit the inserts I did before.
5. So I am expecting first insert to be rolled back and "select count(*) from example" is 0. But now count is 1. Which means first insert is not rolled back even though second insert failed.
Am i missing some details or did I misunderstood something?
Thanks
Sewwandi
-
34. Re: Using Narayana to make two RESTful services transactional
tomjenkinson Sep 6, 2018 4:30 PM (in response to txuser)No problem, I don't think that the REST-AT outbound bridge is ready (mmusgrov will know)
I updated the example with some curl commands though, if you don't call it using the curl commands there won't be a transaction and so there won't be inbound bridging on the service.
-
35. Re: Using Narayana to make two RESTful services transactional
tomjenkinson Sep 6, 2018 4:34 PM (in response to txuser)Well that is not related to briding, I see the logic, so I need to
curl -X GET http://localhost:8080/spring-jta/insert/2
-
36. Re: Using Narayana to make two RESTful services transactional
tomjenkinson Sep 6, 2018 4:41 PM (in response to tomjenkinson)I can see in the debugger that Spring is calling commit on the transaction manager, my guess is that:
return Response.status(Response.Status.BAD_REQUEST)
.entity(ex.getMessage() + " count in db in first get" + count).build();
Does not cause a rollback in Springs interpretation.
-
37. Re: Using Narayana to make two RESTful services transactional
txuser Sep 6, 2018 4:48 PM (in response to tomjenkinson)I have worked with spring transactions. We can use spring transactions to rollback local tx. But I do recall I need to mention springTransactionManager and I have to say at what condition I need to rollback. I am not sure spring automatically rollback transactions.
In this example, I dont have spring tx manager which is something like below. So I was thinking Arjuna transaction Manager will handle it.
<bean id="jdbcTransactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
p:dataSource-ref="dataSource" />
<tx:annotation-driven transaction-manager="jdbcTransactionManager" />
-
38. Re: Using Narayana to make two RESTful services transactional
tomjenkinson Sep 7, 2018 3:57 AM (in response to txuser)When you are using Spring it is that which makes the decision whether to rollback but then it hands off to Narayana in order to effect that rollback. Narayana is the service and Spring is making the decision based on the application semantics.
Of course if Spring asks Narayana to commit, Narayana is in control of the 2PC process and may need to move to rollback (if for example all resources do not return XA_OK from prepare).
-
39. Re: Using Narayana to make two RESTful services transactional
txuser Sep 7, 2018 10:32 AM (in response to tomjenkinson)Ok. So do you think it is because of Spring, our example service is not working properly?
-
40. Re: Using Narayana to make two RESTful services transactional
mmusgrov Sep 7, 2018 10:50 AM (in response to tomjenkinson)Only inbound bridging is supported, ie start a REST-AT transaction and then call a REST service which starts a JTA transaction (such as a db update). When the REST-AT transaction commits so too will the JTA transaction.
Outbound bridging (ie start a JTA transaction and call a REST service) is not a common use case and is not supported.
-
41. Re: Using Narayana to make two RESTful services transactional
tomjenkinson Sep 7, 2018 11:23 AM (in response to txuser)I am thinking you need to somehow tell Spring to rollback a transaction when it gets a BAD_REQUEST returned from it. Either that or perhaps you can just change the class to throw an exception and that might actually work.
-
42. Re: Using Narayana to make two RESTful services transactional
tomjenkinson Sep 7, 2018 11:26 AM (in response to mmusgrov)Yes, OK. So I guess what so long as Sewwandi makes the call over REST from service 1 to service 2 it should be OK?
-
43. Re: Using Narayana to make two RESTful services transactional
txuser Sep 7, 2018 11:41 AM (in response to tomjenkinson)Hi Tom,
I brought spring transaction manager with Narayana and tested few days ago and it rolled back transactions properly. But I am not sure it rolled back because of spring or because of narayana. My goal is to make 2 rest web services transactional. If Spring is the one who is managing transactions, I dont think I can make 2 rest calls transactional. Because I think one rest call is done, it does not maintain the state and cannot be rolled back.
I changed the resource class to throw exception from the method instead of catching it. But now I have this h2 database issue 'Database may be already in use: \"Locked by another process\".".
I will try to fix it and will update you.
Thanks
Sewwandi
-
44. Re: Using Narayana to make two RESTful services transactional
mmusgrov Sep 7, 2018 11:53 AM (in response to txuser)txuser wrote:
I changed the resource class to throw exception from the method instead of catching it. But now I have this h2 database issue 'Database may be already in use: \"Locked by another process\".".
Are you starting a REST-AT transaction and calling 2 remote services each of which starts its own JTA transaction and attempts to update the same h2 database. That setup will not work. It might work if you are updating separate tables and are using a database with better transaction support (such as Oracle). Why not first try getting your example working using distinct databases or a database and a message queue.