Open litheshgopal opened 3 years ago
I've got no real idea what's going on here. Your code doesn't compile (even when obvious variables like the qmgr and channel names are added) so it's rather difficult to know what you are trying to do. But I suspect that you are trying and not quite succeeding in bypassing the automatic connection configuration done by Spring Boot that sets defaults on connections when the CFs are created.
Though you also say you are using v2.0.0 of the starter which is 3 years old, and all kinds of things have changed since then.
I doubt very much that this is one long continuous method, but this is how you have written it. It makes it very hard to debug your code, as it appears that (even though you are on a back level version of the MQ Spring boot starter) your issue is in how you are making use of connection factory beans.
Let me explain why its difficult to debug your code -
You initialise a CachingConnectionFactory as loCacheConnFactory
, which you don't subsequently use.
You base your JmsTemplate on loCachingConnectionFactory
, which is never initialised.
JmsTemplate loJmsTemplate = new JmsTemplate(loCachingConnectionFactory);
and you base your JmsListenerContainerFactory on aCachingConnectionFactory
, which is nowhere else in your code.
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
factory.setConnectionFactory(aCachingConnectionFactory);
I would expect you to be using syntax similar to the configurations, components and beans defined in this sample - https://github.com/ibm-messaging/mq-dev-patterns/tree/master/Spring-JMS/src/main/java/com/ibm/mq/samples/jms/spring/level114
I've got no real idea what's going on here. Your code doesn't compile (even when obvious variables like the qmgr and channel names are added) so it's rather difficult to know what you are trying to do. But I suspect that you are trying and not quite succeeding in bypassing the automatic connection configuration done by Spring Boot that sets defaults on connections when the CFs are created.
Though you also say you are using v2.0.0 of the starter which is 3 years old, and all kinds of things have changed since then.
Hello Mark,
Many thanks for your review and suggestions, I haven't pasted the full code in my previous post because I thought just a sample template would suffice. I have attached my full code here and it will help you to understand what we are trying to implement. I have upgraded the version to latest (2.4.2) as well. Please let me know if you have any further queries on this. I am using multiple Queue Managers (load balanced QM's) and the code is dynamically creating the CF's and get assigned to JmsListeners and JmsTemplate.
Regards, Lithesh
package com.rbs.bdd.mq.clustered.framework.config;
import java.io.InputStream; import java.security.KeyStore; import java.security.Provider; import java.security.Security; import java.util.Enumeration; import java.util.LinkedList; import java.util.List; import java.util.ListIterator; import java.util.Properties; import java.util.StringTokenizer;
import javax.jms.JMSException; import javax.net.ssl.KeyManagerFactory; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSocketFactory; import javax.net.ssl.TrustManager; import javax.net.ssl.TrustManagerFactory;
import org.bouncycastle.jce.provider.BouncyCastleProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; import org.springframework.context.annotation.Scope; import org.springframework.core.io.ClassPathResource; import org.springframework.jms.config.DefaultJmsListenerContainerFactory; import org.springframework.jms.config.SimpleJmsListenerEndpoint; import org.springframework.jms.connection.CachingConnectionFactory; import org.springframework.jms.connection.JmsTransactionManager; import org.springframework.jms.core.JmsTemplate; import org.springframework.jms.listener.DefaultMessageListenerContainer; import org.springframework.jms.support.converter.MappingJackson2MessageConverter; import org.springframework.jms.support.converter.MessageConverter; import org.springframework.jms.support.converter.MessageType; import org.springframework.transaction.PlatformTransactionManager;
import com.ibm.mq.jms.MQQueueConnectionFactory; import com.ibm.msg.client.wmq.WMQConstants; import com.rbs.bdd.crypto.service.DecryptionService; import com.rbs.bdd.mq.clustered.framework.common.exception.VanquishRuntimeException; import com.rbs.bdd.mq.clustered.framework.error.handler.ClusteredErrorHandler; import com.rbs.bdd.mq.clustered.framework.exception.handler.ClusteredExceptionListener; import com.rbs.bdd.mq.clustered.framework.listener.ClusteredMessageListener; import com.rbs.bdd.mq.clustered.framework.listener.impl.ClusteredBDDMessageListenerImpl; import com.rbs.bdd.mq.clustered.framework.model.ClusteredListenerContainerModel; import com.rbs.bdd.mq.clustered.framework.model.ClusteredListenerContainers; import com.rbs.bdd.mq.clustered.framework.model.JmsTemplateModel; import com.rbs.bdd.mq.clustered.framework.model.impl.ClusteredListenerContainersImpl; import com.rbs.bdd.mq.clustered.framework.props.BDDClusteredMQMessageProperties; import com.rbs.bdd.mq.clustered.framework.props.ClusteredJmsProperties; /** --------------------------------------------------------------------------------------------------------
Organization : Royal Bank of Scotland plc. -------------------------------------------------------------------------------------------------------- **/ @Configuration @ComponentScan("com.rbs.bdd") public class IBMMQClusteredConfiguration {
private static final String EMPTY = ""; private static final String TRUE = "true"; private static final String YES = "yes"; private static final String JKS = "JKS"; private static final String COMMA = ","; private static final String SEMICOLON = ";"; private static final String EMPTY_VALUE_PROVIDED = "Empty list supplied for configuration and is not valid!"; private static final boolean AUTO_STARTUP = false; private static int RECEIVE_TIME_OUT = 120000;
/**
/**
@Autowired private DecryptionService decryptionService;
@Autowired private BDDClusteredMQMessageProperties bddClusteredMQMessageProperties;
/**
/**
/**
/**
/**
/**
/**
@return
*/
private List
int loCount = 0;
for (String lsHostName : loHostList)
{
String lsHost = getStringValue(lsHostName);
String lsChannel = getStringFromTheList(loChannelList,loCount);
Integer loPort = getIntegerFromTheList(loPortList,loCount);
String lsManager = getStringFromTheList(loQManagerList,loCount);
String lsSSLPeerName = getStringFromTheList(loSSLPeerNameList,loCount);
Integer loPollingInterval = getIntegerFromTheList(loPollingIntervalList,loCount);
logMessage("lsHost -> "+lsHost);
logMessage("lsChannel -> "+lsChannel);
logMessage("loPort -> "+loPort);
logMessage("lsManager -> "+lsManager);
logMessage("loPollingInterval -> "+loPollingInterval);
logMessage("lsSSLPeerName -> "+lsSSLPeerName);
MQQueueConnectionFactory mqQueueConnectionFactory = new MQQueueConnectionFactory();
mqQueueConnectionFactory.setHostName(lsHost);
mqQueueConnectionFactory.setTransportType(WMQConstants.WMQ_CM_CLIENT);
mqQueueConnectionFactory.setChannel(lsChannel);
mqQueueConnectionFactory.setPort(loPort);
mqQueueConnectionFactory.setQueueManager(lsManager);
mqQueueConnectionFactory.setPollingInterval(loPollingInterval);
mqQueueConnectionFactory = enableSSL(mqQueueConnectionFactory,lsSSLPeerName);
loMQQueueConnectionFactoryList.add(mqQueueConnectionFactory);
loCount = loCount + 1;
}//eof for
} catch (Exception aException) { aException.printStackTrace(); throw new VanquishRuntimeException(aException); } logMessage(" <- bddMQQueueConnectionFactoryList() "+this.getClass().getName()); return loMQQueueConnectionFactoryList; }// EOF bddMQQueueConnectionFactoryList
/**
@param aSSLPeerName */ private MQQueueConnectionFactory enableSSL(MQQueueConnectionFactory aMQQueueConnectionFactory, String aSSLPeerName) { logMessage(" -> enableSSL() "+this.getClass().getName()); try { Properties loSystemProps = System.getProperties();
//-Dorg.cloudfoundry.security.keymanager.enabled=false -Dcom.ibm.mq.cfg.useIBMCipherMappings=false
loSystemProps.setProperty("javax.net.debug", "all");
loSystemProps.setProperty("com.ibm.mq.cfg.useIBMCipherMappings", "false");
loSystemProps.setProperty("org.cloudfoundry.security.keymanager.enabled", "false");
System.setProperties(loSystemProps);
//Used to override any restricted JCE provider issues.
Security.addProvider(new BouncyCastleProvider());
//Security.insertProviderAt(new BouncyCastleJsseProvider(), 1);
//Class.forName("com.sun.net.ssl.internal.ssl.Provider");
Provider[] loProviders = Security.getProviders();
if (loProviders != null)
{
logMessage("!!!!! LISTING ALL THE PROVIDERS !!!!!");
for (Provider loProvider : loProviders)
{
logMessage("Provider -> "+loProvider.toString());
}//eof for
}//eof if
String lsEnabled = getStringValue(jmsProperties.sslEnabled);
if (!isEnabled(lsEnabled)) return aMQQueueConnectionFactory;
String lsKeyStoreName = getStringValue(jmsProperties.sslKeyStoreName);
String lsKeyStorePassPhrase = getStringValue(jmsProperties.sslKeyStorePassPhrase);
lsKeyStorePassPhrase = getDecryptedText(lsKeyStorePassPhrase);
String lsTrustStoreName = getStringValue(jmsProperties.sslTrustStoreName);
String lsTrustStorePassPhrase = getStringValue(jmsProperties.sslTrustStorePassPhrase);
lsTrustStorePassPhrase = getDecryptedText(lsTrustStorePassPhrase);
String lsSslPeerName = getStringValue(aSSLPeerName);
String lsSslCipherSuite = getStringValue(jmsProperties.sslCipherSuite);
String lsSslVersion = getStringValue(jmsProperties.sslVersion);
logMessage("lsKeyStoreName -> "+lsKeyStoreName);
logMessage("lsKeyStorePassPhrase -> "+lsKeyStorePassPhrase);
logMessage("lsTrustStoreName -> "+lsTrustStoreName);
logMessage("lsTrustStorePassPhrase -> "+lsTrustStorePassPhrase);
logMessage("lsSslPeerName -> "+lsSslPeerName);
logMessage("lsSslCipherSuite -> "+lsSslCipherSuite);
logMessage("lsSslVersion -> "+lsKeyStoreName);
if (lsKeyStoreName.length()==0)
{
throw new VanquishRuntimeException(
bddClusteredMQMessageProperties.getPropertyValue("message.filecantbeempty"));
}//eof if
if (lsTrustStoreName.length()==0)
{
throw new VanquishRuntimeException(
bddClusteredMQMessageProperties.getPropertyValue("message.filecantbeempty"));
}//eof if
// instantiate a KeyStore with type JKS
KeyStore loKeyStore = KeyStore.getInstance(JKS);
// load the contents of the KeyStore
InputStream loKSInputStream = new ClassPathResource(lsKeyStoreName).getInputStream();
if (loKSInputStream == null)
{
throw new VanquishRuntimeException(
bddClusteredMQMessageProperties.getPropertyValue("message.filedidntexist"));
}//eof if
loKeyStore.load(loKSInputStream, lsKeyStorePassPhrase.toCharArray());
KeyStore loTrustStore = KeyStore.getInstance(JKS);
// Open our file and read the trust store (no password)
InputStream loTSInputStream = new ClassPathResource(lsTrustStoreName).getInputStream();
if (loTSInputStream == null)
{
throw new VanquishRuntimeException(
bddClusteredMQMessageProperties.getPropertyValue("message.filedidntexist"));
}//eof if
loTrustStore.load(loTSInputStream, lsTrustStorePassPhrase.toCharArray());
// Create a default trust and key manager
TrustManagerFactory loTrustManagerFactory =
TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
KeyManagerFactory loKeyManagerFactory =
KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
// Initialise the managers
loTrustManagerFactory.init(loTrustStore);
loKeyManagerFactory.init(loKeyStore, lsKeyStorePassPhrase.toCharArray());
logMessage("loTrustStore -> "+loTrustStore);
logMessage("loKeyStore -> "+loKeyStore);
logMessage("loTrustManagerFactory -> "+loTrustManagerFactory);
logMessage("loKeyManagerFactory -> "+loKeyManagerFactory);
SSLContext loSSLContext = SSLContext.getInstance(lsSslVersion);
logMessage("loSSLContext -> "+loSSLContext);
loSSLContext.init(loKeyManagerFactory.getKeyManagers(),
loTrustManagerFactory.getTrustManagers(), new java.security.SecureRandom());
logMessage("!!!!! AVAILABLE TRUST MANAGERS !!!!!");
if (loTrustManagerFactory != null)
{
TrustManager[] loTrustManagers = loTrustManagerFactory.getTrustManagers();
for (TrustManager loTrustManager : loTrustManagers)
{
logMessage("loTrustManager-> "+loTrustManager);
}//eof for
}//eof if
logMessage("!!!!! AVAILABLE KEY ALIAS FROM KEYSTORE !!!!!");
if (loKeyStore != null)
{
Enumeration<String> loKeyStoreAlias = loKeyStore.aliases();
while (loKeyStoreAlias.hasMoreElements())
{
String lsKeyAlias = loKeyStoreAlias.nextElement();
logMessage("KEY STORE ALIAS -> "+lsKeyAlias);
}//eof while
}//eof if
logMessage("!!!!! AVAILABLE KEY ALIAS FROM TRUSTSTORE !!!!!");
if (loTrustStore != null)
{
Enumeration<String> loTrustStorAlias = loTrustStore.aliases();
while (loTrustStorAlias.hasMoreElements())
{
String lsTrustKeyAlias = loTrustStorAlias.nextElement();
logMessage("TRUST STORE ALIAS -> "+lsTrustKeyAlias);
}//eof while
}//eof if
// Get an SSLSocketFactory to pass to WMQ
SSLSocketFactory loSSLSocketFactory = loSSLContext.getSocketFactory();
aMQQueueConnectionFactory.setSSLSocketFactory(loSSLSocketFactory);
aMQQueueConnectionFactory.setSSLFipsRequired(false);
if (lsSslCipherSuite.length()>0)
aMQQueueConnectionFactory.setSSLCipherSuite(lsSslCipherSuite);
if (lsSslPeerName.length()>0)
aMQQueueConnectionFactory.setSSLPeerName(lsSslPeerName);
logMessage("!!!!! SUCCESSFULLY CREATED SSL CONTEXT !!!!!");
if (loKSInputStream!=null)
{
logMessage("!!!!< Key store input stream closed >!!!!");
loKSInputStream.close();
}//eof if
if (loTSInputStream!=null)
{
logMessage("!!!!< Trust store input stream closed >!!!!");
loTSInputStream.close();
}//eof if
} catch (JMSException aJMSException) { aJMSException.printStackTrace(); throw new VanquishRuntimeException(aJMSException); } catch (Exception aException) { aException.printStackTrace(); throw new VanquishRuntimeException(aException); }
logMessage(" <- enableSSL() "+this.getClass().getName()); return aMQQueueConnectionFactory; }//eof enableSSL
/**
@return
*/
@Bean(name = "bddCachingMQConnectionFactoryListForSender")
@Primary
public List
List
/**
@return
*/
@Bean(name = "bddCachingMQConnectionFactoryListForListener")
@Primary
public List
List
List
try
{
List
List<MQQueueConnectionFactory> loMQQueueConnectionFactoryList = bddMQQueueConnectionFactoryList();
ListIterator<MQQueueConnectionFactory> loMQQueueConnectionFactoryListIter = loMQQueueConnectionFactoryList.listIterator();
int loCount = 0;
while (loMQQueueConnectionFactoryListIter.hasNext())
{
Integer loCacheSize = loCacheSizeList.get(loCount);
MQQueueConnectionFactory loMQQueueConnectionFactory = loMQQueueConnectionFactoryListIter.next();
CachingConnectionFactory loCacheConnFactory = new CachingConnectionFactory();
loCacheConnFactory.setTargetConnectionFactory(loMQQueueConnectionFactory);
loCacheConnFactory.setSessionCacheSize(loCacheSize);
loCacheConnFactory.setCacheConsumers(true);
loCacheConnFactory.setReconnectOnException(true);
loCachingConnectionFactoryList.add(loCacheConnFactory);
loCount = loCount + 1;
}//eof while
} catch (Exception aException) { aException.printStackTrace(); throw new VanquishRuntimeException(aException); } logMessage(" <- bddCachingMQConnectionFactoryListForListener() "+this.getClass().getName()); return loCachingConnectionFactoryList; }// eof bddCachingMQConnectionFactoryListForListener
/**
/**
/**
@return
*/
@Bean(name = "clusteredJmsTemplateModelListForSender")
public List
logMessage(" loTimeOut -> "+loTimeOut);
logMessage(" count -> "+count);
PlatformTransactionManager loPlatformTransactionManager = loPlatformTransactionManagerList.get(count);
JmsTransactionManager loJmsTransactionManager = (JmsTransactionManager) loPlatformTransactionManager;
logMessage("loCachingConnectionFactory -> "+loCachingConnectionFactory);
logMessage("loJmsTransactionManager -> "+loJmsTransactionManager);
JmsTemplate loJmsTemplate = new JmsTemplate(loCachingConnectionFactory);
loJmsTemplate.setPubSubDomain(false);
loJmsTemplate.setDeliveryPersistent(true);
loJmsTemplate.setReceiveTimeout(loTimeOut);
boolean lbSessionTranscated = getAsBoolean(jmsProperties.sessionTranscated);
logMessage("lbSessionTranscated -> "+lbSessionTranscated);
loJmsTemplate.setSessionTransacted(lbSessionTranscated);
JmsTemplateModel loJmsTemplateModel = new JmsTemplateModel();
loJmsTemplateModel.setJmsTemplate(loJmsTemplate);
loJmsTemplateModel.setCachingConnectionFactory(loCachingConnectionFactory);
loJmsTemplateModel.setPlatformTransactionManager(loJmsTransactionManager);
loJmsTemplateModelList.add(loJmsTemplateModel);
count = count + 1;
}//eof while
} catch (Exception aException) { aException.printStackTrace(); throw new VanquishRuntimeException(aException); } logMessage(" <- clusteredJmsTemplateModelListForSender() "+this.getClass().getName()); return loJmsTemplateModelList; } // eof clusteredJmsTemplateModelListForSender
/**
/**
/**
@return */ @Bean(name = "bddClusteredJmsListenerContainerFactory") @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) public DefaultJmsListenerContainerFactory bddJmsListenerContainerFactory(String aMaxConcurrency, String aMinConcurrency, CachingConnectionFactory aCachingConnectionFactory, PlatformTransactionManager aPlatformTransactionManager) { DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory(); factory.setConnectionFactory(aCachingConnectionFactory); factory.setCacheLevel(DefaultMessageListenerContainer.CACHE_CONSUMER); String lsConcurrency = aMinConcurrency + "-" + aMaxConcurrency; factory.setConcurrency(lsConcurrency); boolean lbSessionTranscated = getAsBoolean(jmsProperties.sessionTranscated); logMessage("lbSessionTranscated -> "+lbSessionTranscated); factory.setSessionTransacted(lbSessionTranscated); factory.setAutoStartup(AUTO_STARTUP); factory.setErrorHandler(vanquishErrorHandler()); Long loTimeOut = getAsLongValue(jmsProperties.listenerReceiveTimeout); if (loTimeOut.longValue() > 0) factory.setReceiveTimeout(loTimeOut);
String lsCacheConsumerEnabled = getStringValue(jmsProperties.cacheConsumerEnabled); if (isEnabled(lsCacheConsumerEnabled)) factory.setCacheLevel(DefaultMessageListenerContainer.CACHE_CONSUMER);
factory.setTransactionManager(aPlatformTransactionManager);
return factory; }// eof bddJmsListenerContainerFactory
/**
/**
/**
@return
*/
@Bean(name = "bddClusteredListenerContainerList")
public List
ClusteredListenerContainersImpl loListenerContainersImpl = (ClusteredListenerContainersImpl) bddClusteredlistenerContainers(loMainContainerList);
//loListenerContainersImpl.setClusteredListenerContainerModelList(loMainContainerList);
List
List
List
List
logMessage(" loMaxConcurrentConsumerList -> "+loMaxConcurrentConsumerList); logMessage(" loIdleTaskExeLimitList -> "+loIdleTaskExeLimitList); logMessage(" loIdleConsumerLimitList -> "+loIdleConsumerLimitList); logMessage(" loConcurrentConsumerList -> "+loConcurrentConsumerList); logMessage(" loMaxMsgPerTaskList -> "+loMaxMsgPerTaskList); logMessage(" loMinConsumerList -> "+loMinConsumerList);
ListIterator
int liIndex = 0; while (loQueueNameListIter.hasNext()) { String lsQueueName = loQueueNameListIter.next();
lsQueueName = getStringValue(lsQueueName);
if (lsQueueName.length()==0) return loMainContainerList;
logMessage(" lsQueueName -> "+lsQueueName);
Integer loMaxConcurrency = loConcurrencyList.get(liIndex);
if (loMaxConcurrency == null) loMaxConcurrency = new Integer(1);
logMessage(" loMaxConcurrency -> "+loMaxConcurrency);
String lsMaxConcurrency = String.valueOf(loMaxConcurrency);
logMessage(" lsMaxConcurrency -> "+lsMaxConcurrency);
String lsMinConsumers = loMinConsumerList.get(liIndex);
logMessage(" lsMinConsumers -> "+lsMinConsumers);
Integer loMaxConcurrentConsumer = getIntegerFromTheList(loMaxConcurrentConsumerList,liIndex);
Integer loIdleTaskExeLimit = getIntegerFromTheList(loIdleTaskExeLimitList,liIndex);
Integer loIdleConsumerLimit = getIntegerFromTheList(loIdleConsumerLimitList,liIndex);
Integer loConcurrentConsumer= getIntegerFromTheList(loConcurrentConsumerList,liIndex);
Integer loMaxMsgPerTask = getIntegerFromTheList(loMaxMsgPerTaskList,liIndex);
logMessage(" loMaxConcurrentConsumer -> "+loMaxConcurrentConsumer);
logMessage(" loIdleTaskExeLimit -> "+loIdleTaskExeLimit);
logMessage(" loIdleConsumerLimit -> "+loIdleConsumerLimit);
logMessage(" loConcurrentConsumer -> "+loConcurrentConsumer);
logMessage(" loMaxMsgPerTask -> "+loMaxMsgPerTask);
for (String lsClassName : loListenerClassesList)
{
lsClassName = getStringValue(lsClassName);
logMessage(" lsQueueName -> "+lsQueueName);
List<CachingConnectionFactory> loCachingConnectionFactoryList =
bddCachingMQConnectionFactoryListForListener();
ListIterator<CachingConnectionFactory> loCachConnFactListIter =
loCachingConnectionFactoryList.listIterator();
List<PlatformTransactionManager> loPlatformTransactionManagerList = jmsTransactionManagerListForListener();
int loCount = 0;
while (loCachConnFactListIter.hasNext())
{
CachingConnectionFactory loCachingConnectionFactory =
loCachConnFactListIter.next();
PlatformTransactionManager loPlatformTransactionManager = loPlatformTransactionManagerList.get(loCount);
ClusteredListenerContainerModel loListenerContainerModel = new ClusteredListenerContainerModel();
loListenerContainerModel.setPlatformTransactionManager(loPlatformTransactionManager);
loListenerContainerModel.setQueueName(lsQueueName);
//Start of newly added code
List<String> loChannelList = getClusteredMQChannelList();
List<String> loQMList = getClusteredMQQueueManagerList();
String lsChannelName = loChannelList.get(loCount);
String lsQueueManagerName = loQMList.get(loCount);
logMessage(" lsChannelName -> "+lsChannelName);
logMessage(" lsQueueManagerName -> "+lsQueueManagerName);
loListenerContainerModel.setCachingConnectionFactory(loCachingConnectionFactory);
loListenerContainerModel.setChannelName(lsChannelName);
loListenerContainerModel.setQueueManagerName(lsQueueManagerName);
//End of newly added code
DefaultJmsListenerContainerFactory loListenerContainerFactory =
bddJmsListenerContainerFactory(lsMaxConcurrency, lsMinConsumers,
loCachingConnectionFactory,
loPlatformTransactionManager);
MQQueueConnectionFactory loMQQueueConnectionFactory = (MQQueueConnectionFactory)
loCachingConnectionFactory.getTargetConnectionFactory();
String lsHostName = loMQQueueConnectionFactory.getHostName();
loListenerContainerModel.setHostName(lsHostName);
ClusteredBDDMessageListenerImpl loBDDMessageListenerImpl =
bddMessageListener(lsClassName,loListenerContainerModel, loPlatformTransactionManager);
SimpleJmsListenerEndpoint loEndPoint = new SimpleJmsListenerEndpoint();
loEndPoint.setMessageListener(loBDDMessageListenerImpl);
loEndPoint.setDestination(lsQueueName);
DefaultMessageListenerContainer loListenerContainer = loListenerContainerFactory.
createListenerContainer(loEndPoint);
loListenerContainer.setMaxConcurrentConsumers(loMaxConcurrentConsumer);
loListenerContainer.setConcurrentConsumers(loConcurrentConsumer);
loListenerContainer.setIdleTaskExecutionLimit(loIdleTaskExeLimit);
loListenerContainer.setMaxMessagesPerTask(loMaxMsgPerTask);
loListenerContainer.setIdleConsumerLimit(loIdleConsumerLimit);
loListenerContainer.setAcceptMessagesWhileStopping(false);
loListenerContainer.setExceptionListener(vanquishExceptionListener());
loListenerContainerModel.setDefaultMessageListenerContainer(loListenerContainer);
loListenerContainerModel.setBDDMessageListenerImpl(loBDDMessageListenerImpl);
loListenerContainersImpl.addListenerContainerModel(loListenerContainerModel);
loMainContainerList.add(loListenerContainerModel);
loCount = loCount + 1;
}//eof inner while going for next QM
}//eof for going for next listener class
liIndex = liIndex + 1;
}//eof while //going for next queue //register listener containers loListenerContainersImpl = (ClusteredListenerContainersImpl) bddClusteredlistenerContainers(loMainContainerList); loListenerContainersImpl.activateListeners(); return loMainContainerList; } // eof bddListenerContainerList
/**
@return */ private Long getAsLong(String aStringValue, long aValue) { logMessage(" -> getAsLong() "+this.getClass().getName()); Long loLongValue = new Long(aValue); if (aStringValue == null) return loLongValue; if (aStringValue.trim().length() == 0) return loLongValue;
String lsStringValue = aStringValue.trim(); loLongValue = Long.parseLong(lsStringValue); logMessage(" <- getAsLong() "+this.getClass().getName()); return loLongValue; }//eof getAsLong
/**
/**
/**
/**
/*
@return
*/
private List
StringTokenizer loTokenizer = new StringTokenizer(aStringValue, COMMA);
while (loTokenizer.hasMoreTokens()) { String lsToken = loTokenizer.nextToken(); if (lsToken != null) lsToken = lsToken.trim(); loStringValueList.add(lsToken); }//eof while logMessage(" <- getAsListString() "+this.getClass().getName()); return loStringValueList; }//eof getAsListString
/**
/**
/**
@return
*/
private List
StringTokenizer loTokenizer = new StringTokenizer(aStringValue, SEMICOLON);
while (loTokenizer.hasMoreTokens()) { String lsToken = loTokenizer.nextToken(); loStringValueList.add(lsToken); }//eof while logMessage(" <- getAsListStringWithSemicolon() "+this.getClass().getName()); return loStringValueList; }//eof getAsListString
/**
@return
*/
private List
StringTokenizer loTokenizer = new StringTokenizer(aStringValue, COMMA);
while (loTokenizer.hasMoreTokens()) { String lsToken = loTokenizer.nextToken(); if (lsToken != null)lsToken = lsToken.trim(); Integer loTokenInt = Integer.parseInt(lsToken); loIntegerValueList.add(loTokenInt); }//eof while logMessage(" <- getAsListInteger() "+this.getClass().getName()); return loIntegerValueList; }//eof getAsListString
/**
@return */ private Long getAsLongValue(String aStringValue) { Long loLongValue = new Long(-1); if (aStringValue == null) return loLongValue; if (aStringValue.trim().length() == 0) return loLongValue;
String lsLongString = aStringValue.trim(); loLongValue = new Long(Long.parseLong(lsLongString)); return loLongValue; }//eof getAsListString
/**
/**
}
**MQ Queue Manager Channel Name is disappearing form the JmsConnectionFactory when we use them across both JmsListener and JmsTemplate
Spring JMS - mq-jms-spring-boot-starter (Version 2.0.0) java version "1.8.0_162" Java(TM) SE Runtime Environment (build 1.8.0_162-b12) Java HotSpot(TM) 64-Bit Server VM (build 25.162-b12, mixed mode)
MQQueueConnectionFactory mqQueueConnectionFactory = new MQQueueConnectionFactory(); mqQueueConnectionFactory.setHostName(lsHost); mqQueueConnectionFactory.setTransportType(WMQConstants.WMQ_CM_CLIENT); mqQueueConnectionFactory.setChannel(lsChannel); mqQueueConnectionFactory.setPort(loPort); mqQueueConnectionFactory.setQueueManager(lsManager); mqQueueConnectionFactory.setPollingInterval(loPollingInterval); mqQueueConnectionFactory.setSSLSocketFactory(loSSLSocketFactory); mqQueueConnectionFactory.setSSLFipsRequired(false); mqQueueConnectionFactory.setSSLCipherSuite(lsSslCipherSuite); mqQueueConnectionFactory.setSSLPeerName(lsSslPeerName);
CachingConnectionFactory loCacheConnFactory = new CachingConnectionFactory(); loCacheConnFactory.setTargetConnectionFactory(mqQueueConnectionFactory); loCacheConnFactory.setSessionCacheSize(loCacheSize); loCacheConnFactory.setCacheConsumers(true); loCacheConnFactory.setReconnectOnException(true);
JmsTransactionManager loJmsTransactionManager = new JmsTransactionManager(loCachingConnectionFactory);
JmsTemplate loJmsTemplate = new JmsTemplate(loCachingConnectionFactory); loJmsTemplate.setPubSubDomain(false); loJmsTemplate.setDeliveryPersistent(true); loJmsTemplate.setReceiveTimeout(loTimeOut); loJmsTemplate.setSessionTransacted(true);
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory(); factory.setConnectionFactory(aCachingConnectionFactory); factory.setCacheLevel(DefaultMessageListenerContainer.CACHE_CONSUMER); factory.setConcurrency("1-5"); factory.setSessionTransacted(lbSessionTranscated); factory.setAutoStartup(true); factory.setReceiveTimeout(loTimeOut); factory.setCacheLevel(DefaultMessageListenerContainer.CACHE_CONSUMER); factory.setTransactionManager(loJmsTransactionManager);
SimpleJmsListenerEndpoint loEndPoint = new SimpleJmsListenerEndpoint(); loEndPoint.setMessageListener(loMessageListenerInstance); loEndPoint.setDestination(lsQueueName);
DefaultMessageListenerContainer loListenerContainer = factory. createListenerContainer(loEndPoint);
loListenerContainer.setMaxConcurrentConsumers(loMaxConcurrentConsumer); loListenerContainer.setConcurrentConsumers(loConcurrentConsumer); loListenerContainer.setIdleTaskExecutionLimit(loIdleTaskExeLimit); loListenerContainer.setMaxMessagesPerTask(loMaxMsgPerTask); loListenerContainer.setIdleConsumerLimit(loIdleConsumerLimit); loListenerContainer.setAcceptMessagesWhileStopping(false);
loJmsTemplate.send(aQueueName, MessageCreator);
2021-06-10T12:32:06.016+01:00 [APP/PROC/WEB/0] [ERR] org.springframework.transaction.CannotCreateTransactionException: Could not create JMS transaction; nested exception is com.ibm.msg.client.jms.DetailedJMSException: JMSWMQ0018: Failed to connect to queue manager '' with connection mode 'Client' and host name 'RBSMQ-RS861AC.server.rbsgrp.net(5111)'. 2021-06-10T12:32:06.016+01:00 [APP/PROC/WEB/0] [ERR] Check the queue manager is started and if running in client mode, check there is a listener running. Please see the linked exception for more information. 2021-06-10T12:32:06.016+01:00 [APP/PROC/WEB/0] [ERR] at org.springframework.jms.connection.JmsTransactionManager.doBegin(JmsTransactionManager.java:234) 2021-06-10T12:32:06.016+01:00 [APP/PROC/WEB/0] [ERR] at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:378) 2021-06-10T12:32:06.016+01:00 [APP/PROC/WEB/0] [ERR] at com.rbs.bdd.mq.clustered.framework.message.sender.impl.ClusteredMessageSenderImpl.sendMessageToQueue(ClusteredMessageSenderImpl.java:128) 2021-06-10T12:32:06.016+01:00 [APP/PROC/WEB/0] [ERR] at com.rbs.bdd.mq.clustered.framework.message.sender.impl.ClusteredMessageSenderImpl.sendMessage(ClusteredMessageSenderImpl.java:73) 2021-06-10T12:32:06.016+01:00 [APP/PROC/WEB/0] [ERR] at com.rbs.bdd.mq.clustered.framework.message.sender.impl.ClusteredVanquishTextMessageSenderImpl.dispatchMessage(ClusteredVanquishTextMessageSenderImpl.java:42) 2021-06-10T12:32:06.016+01:00 [APP/PROC/WEB/0] [ERR] at com.rbs.bdd.api.service.InwardRetrieveServiceImpl.sendMessageToClusteredQueue(InwardRetrieveServiceImpl.java:97) 2021-06-10T12:32:06.017+01:00 [APP/PROC/WEB/0] [ERR] at com.rbs.bdd.api.service.InwardRetrieveServiceImpl.processRetrieveRequest(InwardRetrieveServiceImpl.java:80) 2021-06-10T12:32:06.017+01:00 [APP/PROC/WEB/0] [ERR] at com.rbs.bdd.api.controller.InwardPaymentController.processRetrieveRequest(InwardPaymentController.java:53) 2021-06-10T12:32:06.017+01:00 [APP/PROC/WEB/0] [ERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 2021-06-10T12:32:06.017+01:00 [APP/PROC/WEB/0] [ERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 2021-06-10T12:32:06.017+01:00 [APP/PROC/WEB/0] [ERR] at
When we explicitly set mqQueueConnectionFactory.setChannel(lsChannel); before loJmsTemplate.send(aQueueName, MessageCreator); thing are working as expected! Not sure why channel is Vanished from the pre-configured ConnectionFactory object?**