-
1. Re: How to enlist a custom XAResouce in the spring and start the recovery manager service
tomjenkinson Jan 27, 2016 6:16 AM (in response to zhfeng)1 of 1 people found this helpfulAmos Feng wrote:
Hi,
I currently use the following codes to enlist the custom XAResouce explictly
- @Service
- public class ExampleService {
- private JdbcTemplate jdbc;
- @Autowired
- private JtaTransactionManager transactionManager;
- @Autowired
- public ExampleService(JdbcTemplate jdbc) {
- this.jdbc = jdbc;
- }
- @Transactional
- public void testRecovery() throws Exception {
- Transaction transaction = transactionManager.getTransactionManager().getTransaction();
- transaction.enlistResource(new DummyXAResource(DummyXAResource.faultType.HALT));
- jdbc.execute("insert into example values (1, 'test1')");
- }
- }
I wonder that is there the way to inject the bean of DummyXAResouce and the spring can enlist it in the method with the annotation of Transactional automatically ?
I don't think there is a problem with doing that for a dummy XAResource.
-
2. Re: How to enlist a custom XAResouce in the spring and start the recovery manager service
tomjenkinson Jan 27, 2016 6:25 AM (in response to zhfeng)Amos Feng wrote:
in term of starting the recovery manager service, it looks like the spring does not provide the way to integrate the recovery manager. So it need to setup and run the scanning manually in the application.
I borrow some codes from the ArjunaJTA/recovery and it should work.
- if(args.length == 1) {
- if (args[0].equals("-f")) {
- BeanPopulator.getDefaultInstance(ObjectStoreEnvironmentBean.class).setObjectStoreDir(Util.recoveryStoreDir);
- service.testRecovery();
- } else if (args[0].equals("-r")) {
- RecoverySetup.startRecovery();
- try {
- new DummyRecovery().waitForRecovery();
- service.checkRecord();
- } catch (RuntimeException e) {
- System.err.println(e);
- }
- RecoverySetup.stopRecovery();
- }
- }
Thanks for the input,
Amos
This is the more interesting topic.
@gytis did some work as part of JBTM-2470 to allow the recovery manager to start up when the transaction server does [JBTM-2470] Start embedded RM if -recovery is passed to transaction s… · jbosstm/narayana@37b096f · GitHub
You could do something similar - RecoveryManager.manager().startRecoveryManagerThread()
The real question you need to answer is what is the best way to pass generic resources to the recovery manager. In WildFly we add XAResources via narayana/RecoveryManagerService.java at master · jbosstm/narayana · GitHub where the XAResourceRecovery is established by JCA or proprietary code in the resource adapter. What is the way that existing Spring compliant transaction managers (e.g. Atomikos or Bitronix) are passed these references? It could be they are passed an XAResource for recovery or something that has that anyway.
-
3. Re: How to enlist a custom XAResouce in the spring and start the recovery manager service
tomjenkinson Jan 27, 2016 6:26 AM (in response to tomjenkinson)gytis - sorry my tags didn't work hopefully you see my response above with suggestions about how to investigate passing in XAResources to the recovery manager.
-
4. Re: How to enlist a custom XAResouce in the spring and start the recovery manager service
mmusgrov Jan 27, 2016 6:33 AM (in response to zhfeng)You could take a look at what I did in ceylon (basically I used XARecoveryModule#addXAResourceRecoveryHelper and RecoveryManager#manger()):
ceylon-sdk/ConcreteRecoveryManager.ceylon at master · ceylon/ceylon-sdk · GitHub
and
ceylon-sdk/ConcreteRecoveryManager.ceylon at master · ceylon/ceylon-sdk · GitHub
-
5. Re: How to enlist a custom XAResouce in the spring and start the recovery manager service
tomjenkinson Jan 27, 2016 6:44 AM (in response to mmusgrov)Yep looks good too.
The real question is how to get hold of the XADataSource in ceylon-sdk/ConcreteRecoveryManager.ceylon at master · ceylon/ceylon-sdk · GitHub i.e. who calls registerXAResourceRecoveryDataSource and can we make them do it with JMS connections etc too. I think making the app do it is not ideal.
We could just configure classnames and credentials in the spring beans config to load up an XADataSource XAConnectionFactory and pass it into a new Spring Narayana recovery bean which can call the equivalent of registerXAResourceRecoveryDataSource for us with the spring initialized XADS or whatever.
-
6. Re: How to enlist a custom XAResouce in the spring and start the recovery manager service
zhfeng Jan 28, 2016 3:43 AM (in response to tomjenkinson)It looks like the Atomiks wrapper the XADataSource and XAConnectionFactory to register for recovery
<bean id="xaFactory" class="org.apache.activemq.ActiveMQXAConnectionFactory"> <property name="brokerURL" value="tcp://localhost:61616" /> </bean> <!-- Configure the JMS connector; call init to register for recovery! --> <bean id="ConnectionFactory" class="com.atomikos.jms.AtomikosConnectionFactoryBean" init-method="init" destroy-method="close"> <property name="uniqueResourceName" value="amq1" /> <property name="xaConnectionFactory" ref="xaFactory" /> </bean>
<bean id="dataSource" class="com.atomikos.jdbc.AtomikosDataSourceBean" init-method="init" destroy-method="close"> <property name="uniqueResourceName" value="XA1DBMS" /> <property name="xaDataSource" ref="db1" /> <property name="poolSize" value="3" /> </bean> <bean id="db1" class="com.mysql.jdbc.jdbc2.optional.MysqlXADataSource" lazy-init="true"> <property name="pinGlobalTxToPhysicalConnection" value="true" /> <property name="user" value="root" /> <property name="password" value="pass" /> <property name="url" value="jdbc:mysql://localhost:3306/users" /> </bean>
The wrapper class is "com.atomikos.jms.AtomikosConnectionFactoryBean" and "com.atomikos.jdbc.AtomikosDataSourceBean"
I think Bitronix does the similar things.
-
7. Re: How to enlist a custom XAResouce in the spring and start the recovery manager service
zhfeng Jan 28, 2016 3:46 AM (in response to zhfeng)The property "uniqueResouceName" should be used to recovery.
-
8. Re: How to enlist a custom XAResouce in the spring and start the recovery manager service
tomjenkinson Jan 28, 2016 5:24 AM (in response to zhfeng)Great - I think we should do something equivalent then. When setXaConnectionFactory is called on our bean we can pass it to the XARecoveryModule for scanning.
Please can you prototype this and share your branch on the thread? Unless you feel that is not the correct approach?
gytis - do you agree with that approach and can something similar be done in Spring boot or have you tried something like this already? -
9. Re: How to enlist a custom XAResouce in the spring and start the recovery manager service
gytis Jan 28, 2016 6:04 AM (in response to tomjenkinson)Yes that makes sense. I have not tried anything related to recovery so far. But I am in the process of implementing equivalent beans to AtomikosConnectionFactoryBean and AtomikosDataSourceBean.
-
10. Re: How to enlist a custom XAResouce in the spring and start the recovery manager service
gytis Jan 28, 2016 6:06 AM (in response to gytis)Currently I'm implementing them in order to enlist JDBC and JMS resources to the transaction, but later I have been planning to extend them to add recovery too.
However, currently they are in Spring Boot repository. If we need them for general Spring integration too, I'll have to move them to our source code.
-
11. Re: How to enlist a custom XAResouce in the spring and start the recovery manager service
zhfeng Jan 28, 2016 9:31 AM (in response to gytis)I think we should move them to our source code as the general spring integration need them too. It has to use the TransactionalDriver currently.
-
12. Re: How to enlist a custom XAResouce in the spring and start the recovery manager service
zhfeng Jan 28, 2016 9:34 AM (in response to gytis)It looks like there is a bean in the spring-boot extends AtomikosConnectionFactoryBean
spring-boot/AtomikosConnectionFactoryBean.java at master · spring-projects/spring-boot · GitHub
-
13. Re: How to enlist a custom XAResouce in the spring and start the recovery manager service
gytis Jan 28, 2016 9:40 AM (in response to zhfeng)I know, but since we have to implement it from scratch I've put the code in spring-boot repo. But it's not a problem to move it out.
-
14. Re: How to enlist a custom XAResouce in the spring and start the recovery manager service
tomjenkinson Feb 5, 2016 3:11 AM (in response to gytis)Did you make a decision on where to put this class. Putting as much as we can in our repo will be easier to maintain.