Remote JMS with JTS in wildfly
shabin8780 Oct 14, 2015 3:53 AMHi,
I am trying to implement remote JMS in wildfly for multiple instances using JTS.
I combined these two quickstarts: [quickstart/jts at 9.x · wildfly/quickstart · GitHub] and [quickstart/helloworld-jms at 9.x · wildfly/quickstart · GitHub].
This is my changed code in CustomerManagerEJB class at the application-component-1.
@TransactionAttribute(TransactionAttributeType.REQUIRED) public void createCustomer(String name) throws RemoteException { Customer c1 = new Customer(); c1.setName(name); entityManager.persist(c1); final InvoiceManagerEJB invoiceManager = invoiceManagerHome.create(); Context namingContext = null; try { final Properties env = new Properties(); env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory"); env.put(Context.PROVIDER_URL, System.getProperty(Context.PROVIDER_URL, "http-remoting://127.0.0.1:8081")); env.put(Context.SECURITY_PRINCIPAL, "username"); env.put(Context.SECURITY_CREDENTIALS, "password"); namingContext = new InitialContext(env); ConnectionFactory connectionFactory = (ConnectionFactory) namingContext .lookup("/jms/RemoteConnectionFactory"); Destination destination = (Destination) namingContext.lookup("java:/queue/InvoiceManagerQueue"); try (JMSContext context = connectionFactory.createContext("username", "password")) { log.info("Sending messages with content: message from client"); context.createProducer().send(destination, "message from client"); } } catch (NamingException e) { log.log(Level.SEVERE, e.getMessage(), e); } invoiceManager.createInvoice(name); throw new RuntimeException("test"); }
Connection factory config in server side
<connection-factory name="RemoteConnectionFactory"> <factory-type>XA_GENERIC</factory-type> <connectors> <connector-ref connector-name="http-connector"/> </connectors> <entries> <entry name="java:jboss/exported/jms/RemoteConnectionFactory"/> </entries> </connection-factory>
Eventhough I am throwing a runtime exception at the end, the message "message from client" is coming to the server. Do I need to add some extra configs to make remote jms work with JTS?
Regards,
Shabin