[JBoss Messaging] - Re: Embedded server - how to create JMS Topic?
by Leos.Bitto
Because I have started this thread about embedding the JBoss Messaging server, here is my solution for everybody who would need it:
| import java.util.HashMap;
| import java.util.HashSet;
| import java.util.Map;
| import java.util.Set;
| import org.jboss.messaging.core.config.Configuration;
| import org.jboss.messaging.core.config.TransportConfiguration;
| import org.jboss.messaging.core.config.impl.ConfigurationImpl;
| import org.jboss.messaging.core.remoting.impl.invm.InVMAcceptorFactory;
| import org.jboss.messaging.core.remoting.impl.invm.TransportConstants;
| import org.jboss.messaging.core.server.Messaging;
| import org.jboss.messaging.core.server.MessagingServer;
| import org.jboss.messaging.jms.JBossQueue;
| import org.jboss.messaging.jms.JBossTopic;
| import org.jboss.messaging.utils.SimpleString;
|
| public class EmbeddedServer {
|
| private final MessagingServer server;
|
| public EmbeddedServer() {
| final Set<TransportConfiguration> transports = new HashSet<TransportConfiguration>();
| transports.add(new TransportConfiguration(InVMAcceptorFactory.class.getName()));
| server = createMessagingServer(transports);
| }
|
| public EmbeddedServer(int serverID) {
| final Map<String,Object> params = new HashMap<String,Object>();
| params.put(TransportConstants.SERVER_ID_PROP_NAME, serverID);
| final Set<TransportConfiguration> transports = new HashSet<TransportConfiguration>();
| transports.add(new TransportConfiguration(InVMAcceptorFactory.class.getName(), params));
| server = createMessagingServer(transports);
| }
|
| public static MessagingServer createMessagingServer(Set<TransportConfiguration> transports) {
| final Configuration configuration = new ConfigurationImpl();
| configuration.setPersistenceEnabled(false);
| configuration.setSecurityEnabled(false);
| configuration.setAcceptorConfigurations(transports);
| return Messaging.newMessagingServer(configuration);
| }
|
| public void start() throws Exception {
| server.start();
| }
|
| public void stop() throws Exception {
| server.stop();
| }
|
| public JBossQueue createQueue(String name, boolean temporary) throws Exception {
| final SimpleString q = JBossQueue.createAddressFromName(name);
| server.createQueue(q, q, null, false, temporary);
| return new JBossQueue(name);
| }
|
| public JBossQueue createQueue(String name) throws Exception {
| return createQueue(name, false);
| }
|
| public JBossQueue createTemporaryQueue(String name) throws Exception {
| return createQueue(name, true);
| }
|
| public JBossTopic createTopic(String name, boolean temporary) throws Exception {
| final SimpleString t = JBossTopic.createAddressFromName(name);
| server.createQueue(t, t, new SimpleString("__JBMX=-1"), false, temporary);
| return new JBossTopic(name);
| }
|
| public JBossTopic createTopic(String name) throws Exception {
| return createTopic(name, false);
| }
|
| public JBossTopic createTemporaryTopic(String name) throws Exception {
| return createTopic(name, true);
| }
| }
|
You need javax.jms.(XA)ConnectionFactory, too:
| import java.util.HashMap;
| import java.util.Map;
| import org.jboss.messaging.core.config.TransportConfiguration;
| import org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory;
| import org.jboss.messaging.core.remoting.impl.invm.TransportConstants;
| import org.jboss.messaging.jms.client.JBossConnectionFactory;
|
| public class InVMConnector {
|
| public static final String DEFAULT_NAME = InVMConnectorFactory.class.getName();
|
| public static JBossConnectionFactory createJBossConnectionFactory() {
| return createJBossConnectionFactory(DEFAULT_NAME);
| }
|
| public static JBossConnectionFactory createJBossConnectionFactory(String className) {
| final TransportConfiguration transportConfiguration =
| new TransportConfiguration(className);
| return new JBossConnectionFactory(transportConfiguration);
| }
|
| public static JBossConnectionFactory createJBossConnectionFactory(int serverID) {
| return createJBossConnectionFactory(serverID, DEFAULT_NAME);
| }
|
| public static JBossConnectionFactory createJBossConnectionFactory(int serverID, String className) {
| final Map<String,Object> connectionParams = new HashMap<String,Object>();
| connectionParams.put(TransportConstants.SERVER_ID_PROP_NAME, serverID);
| final TransportConfiguration transportConfiguration =
| new TransportConfiguration(className, connectionParams);
| return new JBossConnectionFactory(transportConfiguration);
| }
|
| }
|
These two classes are designed to be used with the ApplicationContext from Spring Framework, here is a sample configuration:
| <bean id="JBMServer" class="EmbeddedServer" init-method="start" destroy-method="stop" />
|
| <bean id="JBMInVMConnectionFactory" class="InVMConnector" factory-method="createJBossConnectionFactory" depends-on="JBMServer" />
|
| <bean id="JBMtestQueue" factory-bean="JBMServer" factory-method="createQueue">
| <constructor-arg value="testQueue" />
| </bean>
|
| <bean id="JBMtestTopic" factory-bean="JBMServer" factory-method="createTopic">
| <constructor-arg value="testTopic" />
| </bean>
|
This solution is obviously useful only when the message persistence is not needed. If the persistence is needed, running an embedded server seems to be inappropriate - run a standalone server in that case instead.
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4243229#4243229
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4243229
17 years
[JBoss jBPM] - Caused by: javax.resource.ResourceException: Transaction is
by Randysv
I get the following exception when I use a timer in a task-node.
I use an Oracle XA data source.
03:16:06,783 ERROR [LogInterceptor] TransactionRolledbackLocalException in method: public abstract void javax.ejb.TimedObject.ejbTimeout(javax.ejb.Timer), causedBy:
org.hibernate.exception.GenericJDBCException: Cannot open connection
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:52)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:449)
at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167)
at org.hibernate.jdbc.AbstractBatcher.prepareSelectStatement(AbstractBatcher.java:145)
at org.hibernate.id.SequenceGenerator.generate(SequenceGenerator.java:96)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:122)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:56)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:50)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:562)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:550)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:546)
at org.jbpm.logging.db.DbLoggingService.log(DbLoggingService.java:49)
at org.jbpm.svc.save.SaveLogsOperation.save(SaveLogsOperation.java:43)
at org.jbpm.svc.Services.save(Services.java:173)
at org.jbpm.JbpmContext.save(JbpmContext.java:461)
at org.jbpm.JbpmContext.autoSave(JbpmContext.java:691)
at org.jbpm.JbpmContext.close(JbpmContext.java:129)
at org.jbpm.ejb.impl.CommandServiceBean.execute(CommandServiceBean.java:124)
at sun.reflect.GeneratedMethodAccessor596.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.jboss.invocation.Invocation.performCall(Invocation.java:386)
at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:228)
at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:156)
at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:173)
at org.jboss.ejb.plugins.CallValidationInterceptor.invoke(CallValidationInterceptor.java:63)
at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:121)
at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:350)
at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:181)
at org.jboss.ejb.plugins.SecurityInterceptor.process(SecurityInterceptor.java:228)
at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:211)
at org.jboss.ejb.plugins.security.PreSecurityInterceptor.process(PreSecurityInterceptor.java:97)
at org.jboss.ejb.plugins.security.PreSecurityInterceptor.invoke(PreSecurityInterceptor.java:81)
at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:205)
at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:138)
at org.jboss.ejb.SessionContainer.internalInvoke(SessionContainer.java:650)
at org.jboss.ejb.Container.invoke(Container.java:1029)
at org.jboss.ejb.plugins.local.BaseLocalProxyFactory.invoke(BaseLocalProxyFactory.java:436)
at org.jboss.ejb.plugins.local.StatelessSessionProxy.invoke(StatelessSessionProxy.java:103)
at $Proxy162.execute(Unknown Source)
at org.jbpm.ejb.impl.TimerEntityBean.ejbTimeout(TimerEntityBean.java:129)
at sun.reflect.GeneratedMethodAccessor595.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.jboss.invocation.Invocation.performCall(Invocation.java:386)
at org.jboss.ejb.EntityContainer$ContainerInterceptor.invoke(EntityContainer.java:1200)
at org.jboss.ejb.plugins.cmp.jdbc.JDBCRelationInterceptor.invoke(JDBCRelationInterceptor.java:87)
at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invoke(EntitySynchronizationInterceptor.java:284)
at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:156)
at org.jboss.ejb.plugins.EntityReentranceInterceptor.invoke(EntityReentranceInterceptor.java:126)
at org.jboss.ejb.plugins.EntityInstanceInterceptor.invoke(EntityInstanceInterceptor.java:279)
at org.jboss.ejb.plugins.EntityLockInterceptor.invoke(EntityLockInterceptor.java:104)
at org.jboss.ejb.plugins.EntityCreationInterceptor.invoke(EntityCreationInterceptor.java:76)
at org.jboss.ejb.plugins.CallValidationInterceptor.invoke(CallValidationInterceptor.java:63)
at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:121)
at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:350)
at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:181)
at org.jboss.ejb.plugins.SecurityInterceptor.process(SecurityInterceptor.java:228)
at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:211)
at org.jboss.ejb.plugins.security.PreSecurityInterceptor.process(PreSecurityInterceptor.java:97)
at org.jboss.ejb.plugins.security.PreSecurityInterceptor.invoke(PreSecurityInterceptor.java:81)
at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:205)
at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:138)
at org.jboss.ejb.EntityContainer.internalInvoke(EntityContainer.java:533)
at org.jboss.ejb.Container.invoke(Container.java:1029)
at org.jboss.ejb.txtimer.TimedObjectInvokerImpl.callTimeout(TimedObjectInvokerImpl.java:104)
at org.jboss.ejb.txtimer.FixedDelayRetryPolicy$RetryThread.run(FixedDelayRetryPolicy.java:112)
Caused by: org.jboss.util.NestedSQLException: Transaction is not active: tx=TransactionImple < ac, BasicAction: -3f57fd96:cdc8:4a5a8010:b3d status: ActionStatus.ABORT_ONLY >; - nested throwable: (javax.resource.ResourceException: Transaction is not active: tx=TransactionImple < ac, BasicAction: -3f57fd96:cdc8:4a5a8010:b3d status: ActionStatus.ABORT_ONLY >)
at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:95)
at org.hibernate.connection.DatasourceConnectionProvider.getConnection(DatasourceConnectionProvider.java:92)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446)
... 68 more
Caused by: javax.resource.ResourceException: Transaction is not active: tx=TransactionImple < ac, BasicAction: -3f57fd96:cdc8:4a5a8010:b3d status: ActionStatus.ABORT_ONLY >
at org.jboss.resource.connectionmanager.TxConnectionManager.getManagedConnection(TxConnectionManager.java:370)
at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateConnection(BaseConnectionManager2.java:496)
at org.jboss.resource.connectionmanager.BaseConnectionManager2$ConnectionManagerProxy.allocateConnection(BaseConnectionManager2.java:941)
at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:89)
... 70 more
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4243228#4243228
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4243228
17 years