@Test public void testConfigureFactory() throws Exception { String address = "http: int port = 18547; String username = "toto"; String password= "123456789"; ConnectionFactory factory = new ConnectionFactory(); Assert.assertNotSame( address, factory.getHost()); Assert.assertNotSame( port, factory.getPort()); Map<String,String> configuration = new HashMap<> (); configuration.put( RABBITMQ_SERVER_IP, "http: configuration.put( RABBITMQ_SERVER_USERNAME, username ); configuration.put( RABBITMQ_SERVER_PASSWORD, password ); RabbitMqUtils.configureFactory( factory, configuration ); Assert.assertEquals( address, factory.getHost()); Assert.assertEquals( port, factory.getPort()); Assert.assertEquals( username, factory.getUsername()); Assert.assertEquals( password, factory.getPassword()); }
public static void configureFactory( ConnectionFactory factory, Map<String,String> configuration ) throws IOException { final Logger logger = Logger.getLogger( RabbitMqUtils.class.getName()); logger.fine( "Configuring a connection factory for RabbitMQ." ); String messageServerIp = configuration.get( RABBITMQ_SERVER_IP ); if( messageServerIp != null ) { Map.Entry<String,Integer> entry = Utils.findUrlAndPort( messageServerIp ); factory.setHost( entry.getKey()); if( entry.getValue() > 0 ) factory.setPort( entry.getValue()); } factory.setUsername( configuration.get( RABBITMQ_SERVER_USERNAME )); factory.setPassword( configuration.get( RABBITMQ_SERVER_PASSWORD )); factory.setConnectionTimeout( 5000 ); factory.setAutomaticRecoveryEnabled( true ); factory.setNetworkRecoveryInterval( 10000 ); factory.setTopologyRecoveryEnabled( true ); if( Boolean.parseBoolean( configuration.get( RABBITMQ_USE_SSL ))) { logger.fine( "Connection factory for RabbitMQ: SSL is used." ); InputStream clientIS = null; InputStream storeIS = null; try { clientIS = new FileInputStream( configuration.get( RABBITMQ_SSL_KEY_STORE_PATH )); storeIS = new FileInputStream( configuration.get( RABBITMQ_SSL_TRUST_STORE_PATH )); char[] keyStorePassphrase = configuration.get( RABBITMQ_SSL_KEY_STORE_PASSPHRASE ).toCharArray(); KeyStore ks = KeyStore.getInstance( getValue( configuration, RABBITMQ_SSL_KEY_STORE_TYPE, DEFAULT_SSL_KEY_STORE_TYPE )); ks.load( clientIS, keyStorePassphrase ); String value = getValue( configuration, RABBITMQ_SSL_KEY_MNGR_FACTORY, DEFAULT_SSL_MNGR_FACTORY ); KeyManagerFactory kmf = KeyManagerFactory.getInstance( value ); kmf.init( ks, keyStorePassphrase ); char[] trustStorePassphrase = configuration.get( RABBITMQ_SSL_TRUST_STORE_PASSPHRASE ).toCharArray(); KeyStore tks = KeyStore.getInstance( getValue( configuration, RABBITMQ_SSL_TRUST_STORE_TYPE, DEFAULT_SSL_TRUST_STORE_TYPE )); tks.load( storeIS, trustStorePassphrase ); value = getValue( configuration, RABBITMQ_SSL_TRUST_MNGR_FACTORY, DEFAULT_SSL_MNGR_FACTORY ); TrustManagerFactory tmf = TrustManagerFactory.getInstance( value ); tmf.init( tks ); SSLContext c = SSLContext.getInstance( getValue( configuration, RABBITMQ_SSL_PROTOCOL, DEFAULT_SSL_PROTOCOL )); c.init( kmf.getKeyManagers(), tmf.getTrustManagers(), null ); factory.useSslProtocol( c ); } catch( GeneralSecurityException e ) { throw new IOException( "SSL configuration for the RabbitMQ factory failed.", e ); } finally { Utils.closeQuietly( storeIS ); Utils.closeQuietly( clientIS ); } } }
RabbitMqUtils { public static void configureFactory( ConnectionFactory factory, Map<String,String> configuration ) throws IOException { final Logger logger = Logger.getLogger( RabbitMqUtils.class.getName()); logger.fine( "Configuring a connection factory for RabbitMQ." ); String messageServerIp = configuration.get( RABBITMQ_SERVER_IP ); if( messageServerIp != null ) { Map.Entry<String,Integer> entry = Utils.findUrlAndPort( messageServerIp ); factory.setHost( entry.getKey()); if( entry.getValue() > 0 ) factory.setPort( entry.getValue()); } factory.setUsername( configuration.get( RABBITMQ_SERVER_USERNAME )); factory.setPassword( configuration.get( RABBITMQ_SERVER_PASSWORD )); factory.setConnectionTimeout( 5000 ); factory.setAutomaticRecoveryEnabled( true ); factory.setNetworkRecoveryInterval( 10000 ); factory.setTopologyRecoveryEnabled( true ); if( Boolean.parseBoolean( configuration.get( RABBITMQ_USE_SSL ))) { logger.fine( "Connection factory for RabbitMQ: SSL is used." ); InputStream clientIS = null; InputStream storeIS = null; try { clientIS = new FileInputStream( configuration.get( RABBITMQ_SSL_KEY_STORE_PATH )); storeIS = new FileInputStream( configuration.get( RABBITMQ_SSL_TRUST_STORE_PATH )); char[] keyStorePassphrase = configuration.get( RABBITMQ_SSL_KEY_STORE_PASSPHRASE ).toCharArray(); KeyStore ks = KeyStore.getInstance( getValue( configuration, RABBITMQ_SSL_KEY_STORE_TYPE, DEFAULT_SSL_KEY_STORE_TYPE )); ks.load( clientIS, keyStorePassphrase ); String value = getValue( configuration, RABBITMQ_SSL_KEY_MNGR_FACTORY, DEFAULT_SSL_MNGR_FACTORY ); KeyManagerFactory kmf = KeyManagerFactory.getInstance( value ); kmf.init( ks, keyStorePassphrase ); char[] trustStorePassphrase = configuration.get( RABBITMQ_SSL_TRUST_STORE_PASSPHRASE ).toCharArray(); KeyStore tks = KeyStore.getInstance( getValue( configuration, RABBITMQ_SSL_TRUST_STORE_TYPE, DEFAULT_SSL_TRUST_STORE_TYPE )); tks.load( storeIS, trustStorePassphrase ); value = getValue( configuration, RABBITMQ_SSL_TRUST_MNGR_FACTORY, DEFAULT_SSL_MNGR_FACTORY ); TrustManagerFactory tmf = TrustManagerFactory.getInstance( value ); tmf.init( tks ); SSLContext c = SSLContext.getInstance( getValue( configuration, RABBITMQ_SSL_PROTOCOL, DEFAULT_SSL_PROTOCOL )); c.init( kmf.getKeyManagers(), tmf.getTrustManagers(), null ); factory.useSslProtocol( c ); } catch( GeneralSecurityException e ) { throw new IOException( "SSL configuration for the RabbitMQ factory failed.", e ); } finally { Utils.closeQuietly( storeIS ); Utils.closeQuietly( clientIS ); } } } }
RabbitMqUtils { public static void configureFactory( ConnectionFactory factory, Map<String,String> configuration ) throws IOException { final Logger logger = Logger.getLogger( RabbitMqUtils.class.getName()); logger.fine( "Configuring a connection factory for RabbitMQ." ); String messageServerIp = configuration.get( RABBITMQ_SERVER_IP ); if( messageServerIp != null ) { Map.Entry<String,Integer> entry = Utils.findUrlAndPort( messageServerIp ); factory.setHost( entry.getKey()); if( entry.getValue() > 0 ) factory.setPort( entry.getValue()); } factory.setUsername( configuration.get( RABBITMQ_SERVER_USERNAME )); factory.setPassword( configuration.get( RABBITMQ_SERVER_PASSWORD )); factory.setConnectionTimeout( 5000 ); factory.setAutomaticRecoveryEnabled( true ); factory.setNetworkRecoveryInterval( 10000 ); factory.setTopologyRecoveryEnabled( true ); if( Boolean.parseBoolean( configuration.get( RABBITMQ_USE_SSL ))) { logger.fine( "Connection factory for RabbitMQ: SSL is used." ); InputStream clientIS = null; InputStream storeIS = null; try { clientIS = new FileInputStream( configuration.get( RABBITMQ_SSL_KEY_STORE_PATH )); storeIS = new FileInputStream( configuration.get( RABBITMQ_SSL_TRUST_STORE_PATH )); char[] keyStorePassphrase = configuration.get( RABBITMQ_SSL_KEY_STORE_PASSPHRASE ).toCharArray(); KeyStore ks = KeyStore.getInstance( getValue( configuration, RABBITMQ_SSL_KEY_STORE_TYPE, DEFAULT_SSL_KEY_STORE_TYPE )); ks.load( clientIS, keyStorePassphrase ); String value = getValue( configuration, RABBITMQ_SSL_KEY_MNGR_FACTORY, DEFAULT_SSL_MNGR_FACTORY ); KeyManagerFactory kmf = KeyManagerFactory.getInstance( value ); kmf.init( ks, keyStorePassphrase ); char[] trustStorePassphrase = configuration.get( RABBITMQ_SSL_TRUST_STORE_PASSPHRASE ).toCharArray(); KeyStore tks = KeyStore.getInstance( getValue( configuration, RABBITMQ_SSL_TRUST_STORE_TYPE, DEFAULT_SSL_TRUST_STORE_TYPE )); tks.load( storeIS, trustStorePassphrase ); value = getValue( configuration, RABBITMQ_SSL_TRUST_MNGR_FACTORY, DEFAULT_SSL_MNGR_FACTORY ); TrustManagerFactory tmf = TrustManagerFactory.getInstance( value ); tmf.init( tks ); SSLContext c = SSLContext.getInstance( getValue( configuration, RABBITMQ_SSL_PROTOCOL, DEFAULT_SSL_PROTOCOL )); c.init( kmf.getKeyManagers(), tmf.getTrustManagers(), null ); factory.useSslProtocol( c ); } catch( GeneralSecurityException e ) { throw new IOException( "SSL configuration for the RabbitMQ factory failed.", e ); } finally { Utils.closeQuietly( storeIS ); Utils.closeQuietly( clientIS ); } } } private  RabbitMqUtils(); }
RabbitMqUtils { public static void configureFactory( ConnectionFactory factory, Map<String,String> configuration ) throws IOException { final Logger logger = Logger.getLogger( RabbitMqUtils.class.getName()); logger.fine( "Configuring a connection factory for RabbitMQ." ); String messageServerIp = configuration.get( RABBITMQ_SERVER_IP ); if( messageServerIp != null ) { Map.Entry<String,Integer> entry = Utils.findUrlAndPort( messageServerIp ); factory.setHost( entry.getKey()); if( entry.getValue() > 0 ) factory.setPort( entry.getValue()); } factory.setUsername( configuration.get( RABBITMQ_SERVER_USERNAME )); factory.setPassword( configuration.get( RABBITMQ_SERVER_PASSWORD )); factory.setConnectionTimeout( 5000 ); factory.setAutomaticRecoveryEnabled( true ); factory.setNetworkRecoveryInterval( 10000 ); factory.setTopologyRecoveryEnabled( true ); if( Boolean.parseBoolean( configuration.get( RABBITMQ_USE_SSL ))) { logger.fine( "Connection factory for RabbitMQ: SSL is used." ); InputStream clientIS = null; InputStream storeIS = null; try { clientIS = new FileInputStream( configuration.get( RABBITMQ_SSL_KEY_STORE_PATH )); storeIS = new FileInputStream( configuration.get( RABBITMQ_SSL_TRUST_STORE_PATH )); char[] keyStorePassphrase = configuration.get( RABBITMQ_SSL_KEY_STORE_PASSPHRASE ).toCharArray(); KeyStore ks = KeyStore.getInstance( getValue( configuration, RABBITMQ_SSL_KEY_STORE_TYPE, DEFAULT_SSL_KEY_STORE_TYPE )); ks.load( clientIS, keyStorePassphrase ); String value = getValue( configuration, RABBITMQ_SSL_KEY_MNGR_FACTORY, DEFAULT_SSL_MNGR_FACTORY ); KeyManagerFactory kmf = KeyManagerFactory.getInstance( value ); kmf.init( ks, keyStorePassphrase ); char[] trustStorePassphrase = configuration.get( RABBITMQ_SSL_TRUST_STORE_PASSPHRASE ).toCharArray(); KeyStore tks = KeyStore.getInstance( getValue( configuration, RABBITMQ_SSL_TRUST_STORE_TYPE, DEFAULT_SSL_TRUST_STORE_TYPE )); tks.load( storeIS, trustStorePassphrase ); value = getValue( configuration, RABBITMQ_SSL_TRUST_MNGR_FACTORY, DEFAULT_SSL_MNGR_FACTORY ); TrustManagerFactory tmf = TrustManagerFactory.getInstance( value ); tmf.init( tks ); SSLContext c = SSLContext.getInstance( getValue( configuration, RABBITMQ_SSL_PROTOCOL, DEFAULT_SSL_PROTOCOL )); c.init( kmf.getKeyManagers(), tmf.getTrustManagers(), null ); factory.useSslProtocol( c ); } catch( GeneralSecurityException e ) { throw new IOException( "SSL configuration for the RabbitMQ factory failed.", e ); } finally { Utils.closeQuietly( storeIS ); Utils.closeQuietly( clientIS ); } } } private  RabbitMqUtils(); static void configureFactory( ConnectionFactory factory, Map<String,String> configuration ); static void closeConnection( Channel channel ); static void declareApplicationExchanges( String domain, String applicationName, Channel channel ); static void declareGlobalExchanges( String domain, Channel channel ); static String buildExchangeNameForAgent( String domain, String applicationName ); static String buildExchangeNameForTheDm( String domain ); static String buildExchangeNameForInterApp( String domain ); static String buildExchangeName( MessagingContext ctx ); }
RabbitMqUtils { public static void configureFactory( ConnectionFactory factory, Map<String,String> configuration ) throws IOException { final Logger logger = Logger.getLogger( RabbitMqUtils.class.getName()); logger.fine( "Configuring a connection factory for RabbitMQ." ); String messageServerIp = configuration.get( RABBITMQ_SERVER_IP ); if( messageServerIp != null ) { Map.Entry<String,Integer> entry = Utils.findUrlAndPort( messageServerIp ); factory.setHost( entry.getKey()); if( entry.getValue() > 0 ) factory.setPort( entry.getValue()); } factory.setUsername( configuration.get( RABBITMQ_SERVER_USERNAME )); factory.setPassword( configuration.get( RABBITMQ_SERVER_PASSWORD )); factory.setConnectionTimeout( 5000 ); factory.setAutomaticRecoveryEnabled( true ); factory.setNetworkRecoveryInterval( 10000 ); factory.setTopologyRecoveryEnabled( true ); if( Boolean.parseBoolean( configuration.get( RABBITMQ_USE_SSL ))) { logger.fine( "Connection factory for RabbitMQ: SSL is used." ); InputStream clientIS = null; InputStream storeIS = null; try { clientIS = new FileInputStream( configuration.get( RABBITMQ_SSL_KEY_STORE_PATH )); storeIS = new FileInputStream( configuration.get( RABBITMQ_SSL_TRUST_STORE_PATH )); char[] keyStorePassphrase = configuration.get( RABBITMQ_SSL_KEY_STORE_PASSPHRASE ).toCharArray(); KeyStore ks = KeyStore.getInstance( getValue( configuration, RABBITMQ_SSL_KEY_STORE_TYPE, DEFAULT_SSL_KEY_STORE_TYPE )); ks.load( clientIS, keyStorePassphrase ); String value = getValue( configuration, RABBITMQ_SSL_KEY_MNGR_FACTORY, DEFAULT_SSL_MNGR_FACTORY ); KeyManagerFactory kmf = KeyManagerFactory.getInstance( value ); kmf.init( ks, keyStorePassphrase ); char[] trustStorePassphrase = configuration.get( RABBITMQ_SSL_TRUST_STORE_PASSPHRASE ).toCharArray(); KeyStore tks = KeyStore.getInstance( getValue( configuration, RABBITMQ_SSL_TRUST_STORE_TYPE, DEFAULT_SSL_TRUST_STORE_TYPE )); tks.load( storeIS, trustStorePassphrase ); value = getValue( configuration, RABBITMQ_SSL_TRUST_MNGR_FACTORY, DEFAULT_SSL_MNGR_FACTORY ); TrustManagerFactory tmf = TrustManagerFactory.getInstance( value ); tmf.init( tks ); SSLContext c = SSLContext.getInstance( getValue( configuration, RABBITMQ_SSL_PROTOCOL, DEFAULT_SSL_PROTOCOL )); c.init( kmf.getKeyManagers(), tmf.getTrustManagers(), null ); factory.useSslProtocol( c ); } catch( GeneralSecurityException e ) { throw new IOException( "SSL configuration for the RabbitMQ factory failed.", e ); } finally { Utils.closeQuietly( storeIS ); Utils.closeQuietly( clientIS ); } } } private  RabbitMqUtils(); static void configureFactory( ConnectionFactory factory, Map<String,String> configuration ); static void closeConnection( Channel channel ); static void declareApplicationExchanges( String domain, String applicationName, Channel channel ); static void declareGlobalExchanges( String domain, Channel channel ); static String buildExchangeNameForAgent( String domain, String applicationName ); static String buildExchangeNameForTheDm( String domain ); static String buildExchangeNameForInterApp( String domain ); static String buildExchangeName( MessagingContext ctx );  }