Setting multiple factories to connect to solace in JMS

Options
guansheng
guansheng Member Posts: 1

I want to establish multiple factory connections in the program at the same time, but I find that after establishing the connection, JMS will not receive the information sent by solace. Here is the code for establishing the connection. Please forgive me for the help of the solution

@Value("${solace.ssl.host}")
private String host;
@Value("#{${solace.ssl.vpn}}")
private Map<String,String> vpns;
@Value("#{${solace.ssl.username}}")
private Map<String,String> userNames;
@Value("${solace.ssl.trustStore}")
private String trustStore;
@Value("${solace.ssl.trustStorePassword}")
private String trustStorePassword;
@Value("${solace.ssl.keyStore}")
private String keyStore;
@Value("${solace.ssl.keyStorePassword}")
private String keyStorePassword;
@Value("${solace.ssl.authenticationScheme}")
private String authenticationScheme;

/**
 * SCSTAR
 * @param connectionFactory
 * @param errorHandler
 * @return
 * @throws Exception
 */
@Bean
public DefaultJmsListenerContainerFactory cFactory(SolConnectionFactory connectionFactory, DemoErrorHandler errorHandler) throws Exception {
    DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
    factory.setConnectionFactory(connectionFactory);
    factory.setErrorHandler(errorHandler);
    return factory;
}


/**
 * SCSTAR
 * @param connectionFactory
 * @param errorHandler
 * @return
 * @throws Exception
 */
@Bean
public JmsListenerContainerFactory<?> starQueueFactory(SolConnectionFactory connectionFactory, DemoErrorHandler errorHandler) throws Exception {
    DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
    factory.setConnectionFactory(setSolConnectionFactoryParam(connectionFactory,"SCSTAR"));
    factory.setPubSubDomain(Boolean.FALSE);
    factory.setErrorHandler(errorHandler);
    return factory;
}
/**
 * SCSTAR
 * @param connectionFactory
 * @param errorHandler
 * @return
 * @throws Exception
 */
@Bean
public JmsListenerContainerFactory<?> starTopicFactory(SolConnectionFactory connectionFactory, DemoErrorHandler errorHandler) throws Exception {
    DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
    factory.setConnectionFactory(setSolConnectionFactoryParam(connectionFactory,"SCSTAR"));
    factory.setPubSubDomain(Boolean.TRUE);
    factory.setErrorHandler(errorHandler);
    return factory;
}

/**
 * RTA
 * @param connectionFactory
 * @param errorHandler
 * @return
 * @throws Exception
 */
@Bean
public JmsListenerContainerFactory<?> rsaFactory(SolConnectionFactory connectionFactory, DemoErrorHandler errorHandler) throws Exception {
    DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
    factory.setConnectionFactory(setSolConnectionFactoryParam(connectionFactory,"RTA"));
    factory.setErrorHandler(errorHandler);
    return factory;
}

/**
 * ccsService
 * @param connectionFactory
 * @param errorHandler
 * @return
 * @throws Exception
 */
@Bean
public JmsListenerContainerFactory<?> ccsServiceFactory(SolConnectionFactory connectionFactory, DemoErrorHandler errorHandler) throws Exception {
    DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
    factory.setConnectionFactory(setSolConnectionFactoryParam(connectionFactory,"CCSSERVICES"));
    factory.setErrorHandler(errorHandler);
    return factory;
}

/**
 * ccsReport
 * @param connectionFactory
 * @param errorHandler
 * @return
 * @throws Exception
 */
@Bean
public JmsListenerContainerFactory<?> ccsReportFactory(SolConnectionFactory connectionFactory, DemoErrorHandler errorHandler) throws Exception {
    DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
    factory.setConnectionFactory(setSolConnectionFactoryParam(connectionFactory,"CCSSERVICES"));
    factory.setErrorHandler(errorHandler);
    return factory;
}



private SolConnectionFactory setSolConnectionFactoryParam(SolConnectionFactory connectionFactory,String param){
    connectionFactory.setHost(host);
    connectionFactory.setUsername(userNames.get(param));
    connectionFactory.setVPN(vpns.get(param));
    connectionFactory.setSSLExcludedProtocols("sslv3,tlsv1,tlsv1.1");
    connectionFactory.setSSLTrustStore(trustStore);
    connectionFactory.setSSLTrustStorePassword(trustStorePassword);
    connectionFactory.setSSLKeyStore(keyStore);
    connectionFactory.setSSLKeyStorePassword(keyStorePassword);
    connectionFactory.setAuthenticationScheme(authenticationScheme);
    return  connectionFactory;
}


@Service
public class DemoErrorHandler implements ErrorHandler {
    @Override
    public void handleError(Throwable t) {
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        PrintStream ps = new PrintStream(os);
        t.printStackTrace(ps);
        try {
            String output = os.toString("UTF8");
            logger.error("============= Error processing message: " + t.getMessage()+"\n"+output);
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}