Class SpringJmsMatsFactoryProducer

java.lang.Object
io.mats3.spring.jms.factories.SpringJmsMatsFactoryProducer

public class SpringJmsMatsFactoryProducer extends Object
Provides an easy way to get hold of the most probable JmsMatsFactory transaction manager configuration in the Spring world (using JmsMatsTransactionManager_JmsAndSpringManagedSqlTx, or only the JmsMatsTransactionManager_Jms if no DataSource is needed). You may either supply a DataSource, or a Spring PlatformTransactionManager (typically DataSourceTransactionManager or HibernateTransactionManager). The code here is very simple, really just creating the MatsFactory normally and then wrapping it up in a SpringJmsMatsFactoryWrapper which provides hook-in to the Spring context (read more about those hook-in features on its JavaDoc).

NOTE: It returns an instance of SpringJmsMatsFactoryWrapper, which it is assumed that you put in the Spring context as a bean, so that Spring property injection and @PostConstruct is run on it. If you instead employ a FactoryBean (e.g. because you have made a cool Mats single-annotation-configuration solution for your multiple codebases), then you need to invoke SpringJmsMatsFactoryWrapper.postConstructForFactoryBean(Environment, ApplicationContext) - read up!

See Also:
  • Constructor Details

    • SpringJmsMatsFactoryProducer

      public SpringJmsMatsFactoryProducer()
  • Method Details

    • createSpringDataSourceTxMatsFactory

      public static SpringJmsMatsFactoryWrapper createSpringDataSourceTxMatsFactory(String appName, String appVersion, MatsSerializer<?> matsSerializer, javax.jms.ConnectionFactory jmsConnectionFactory, DataSource sqlDataSource)
      If you need a MatsFactory employing Spring's DataSourceTransactionManager (which you probably do in a Spring environment utilizing SQL), this is your factory method.

      Usage: Make a @Bean-annotated method which returns the result of this method, or employ a Spring FactoryBean where you then need to invoke SpringJmsMatsFactoryWrapper.postConstructForFactoryBean(Environment, ApplicationContext).

      Parameters:
      appName - the containing application's name (for debugging purposes, you'll find it in the trace).
      appVersion - the containing application's version (for debugging purposes, you'll find it in the trace).
      matsSerializer - the JmsMatsFactory utilizes the MatsSerializer, so you need to provide one. (It is probably the one from the 'mats-serial-json' package).
      jmsConnectionFactory - the JMS ConnectionFactory to fetch JMS Connections from, using ConnectionFactory.createConnection(). It is assumed that if username and password is needed, you have configured that on the ConnectionFactory.
      sqlDataSource - the SQL DataSource which to stash into a Spring DataSourceTransactionManager, and from which SQL Connections are fetched from, using DataSource.getConnection(). It is assumed that if username and password is needed, you have configured that on the DataSource.
      Returns:
      the produced SpringJmsMatsFactoryWrapper
    • createSpringPlatformTransactionManagerTxMatsFactory

      public static SpringJmsMatsFactoryWrapper createSpringPlatformTransactionManagerTxMatsFactory(String appName, String appVersion, MatsSerializer<?> matsSerializer, javax.jms.ConnectionFactory jmsConnectionFactory, org.springframework.transaction.PlatformTransactionManager platformTransactionManager)
      If you need a MatsFactory employing a PlatformTransactionManager of your choosing, which you quite possibly want in a Spring environment using e.g. Spring JDBC or Hibernate, this is your factory method.

      Usage: Make a @Bean-annotated method which returns the result of this method, or employ a Spring FactoryBean where you then need to invoke SpringJmsMatsFactoryWrapper.postConstructForFactoryBean(Environment, ApplicationContext).

      Parameters:
      appName - the containing application's name (for debugging purposes, you'll find it in the trace).
      appVersion - the containing application's version (for debugging purposes, you'll find it in the trace).
      matsSerializer - the JmsMatsFactory utilizes the MatsSerializer, so you need to provide one. (It is probably the one from the 'mats-serial-json' package).
      jmsConnectionFactory - the JMS ConnectionFactory to fetch JMS Connections from, using ConnectionFactory.createConnection(). It is assumed that if username and password is needed, you have configured that on the ConnectionFactory.
      platformTransactionManager - the PlatformTransactionManager (typically DataSourceTransactionManager or HibernateTransactionManager) that the MatsFactory should employ.
      Returns:
      the produced SpringJmsMatsFactoryWrapper
    • createJmsTxOnlyMatsFactory

      public static SpringJmsMatsFactoryWrapper createJmsTxOnlyMatsFactory(String appName, String appVersion, MatsSerializer<?> matsSerializer, javax.jms.ConnectionFactory jmsConnectionFactory)
      If you need a MatsFactory that only handles the JMS transactions, this is your factory method - but if you DO make any database calls within any Mats endpoint lambda, you will now have no or poor transactional demarcation, use createSpringDataSourceTxMatsFactory(..) instead.

      Usage: Make a @Bean-annotated method which returns the result of this method, or employ a Spring FactoryBean where you then need to invoke SpringJmsMatsFactoryWrapper.postConstructForFactoryBean(Environment, ApplicationContext).

      Parameters:
      appName - the containing application's name (for debugging purposes, you'll find it in the trace).
      appVersion - the containing application's version (for debugging purposes, you'll find it in the trace).
      matsSerializer - the JmsMatsFactory utilizes the MatsSerializer, so you need to provide one. (It is probably the one from the 'mats-serial-json' package).
      jmsConnectionFactory - the JMS ConnectionFactory to fetch JMS Connections from, using ConnectionFactory.createConnection(). It is assumed that if username and password is needed, you have configured that on the ConnectionFactory.
      Returns:
      the produced SpringJmsMatsFactoryWrapper