jhalterman / lyra

High availability RabbitMQ client
Apache License 2.0
262 stars 74 forks source link

ThreadFactory missing in ConnectionOptions.copy() #54

Closed stuemke closed 7 years ago

stuemke commented 9 years ago

Hi,

I want to use a thread factory to start connection threads as daemon threads. When creating a new connection with Connections.create(ConnectionOptions options, Config config), the pamater options containes the ConnectionFactory which containes the ThreadFactory.

ThreadFactory threadFactory = new ThreadFactoryBuilder().setDaemon(true).setNameFormat("foo").build();
connectionFactory.setThreadFactory(threadFactory);
ConnectionOptions connectionOptions = new ConnectionOptions(connectionFactory);
Connection connection = Connections.create(connectionOptions, getConnectionConfig());

On creation of the ConnectionHandler a copy of the options is used by calling options.copy().

 ConnectionHandler handler = new ConnectionHandler(options.copy(), new Config(config));

The copy method calls a constructor of ConnectionOptions which creates a complete new ConnectionFactory and copies some of the attributes. Unfortunately the ThreadFactory is not copied.

private ConnectionOptions(ConnectionOptions options) {
    factory = new ConnectionFactory();
    factory.setClientProperties(options.factory.getClientProperties());
    factory.setConnectionTimeout(options.factory.getConnectionTimeout());
    factory.setHost(options.factory.getHost());
    factory.setPort(options.factory.getPort());
    factory.setUsername(options.factory.getUsername());
    factory.setPassword(options.factory.getPassword());
    factory.setVirtualHost(options.factory.getVirtualHost());
    factory.setRequestedChannelMax(options.factory.getRequestedChannelMax());
    factory.setRequestedFrameMax(options.factory.getRequestedFrameMax());
    factory.setRequestedHeartbeat(options.factory.getRequestedHeartbeat());
    factory.setSaslConfig(options.factory.getSaslConfig());
    factory.setSocketFactory(options.factory.getSocketFactory());
    hosts = options.hosts;
    addresses = options.addresses;
    name = options.name;
    executor = options.executor;
  }

At the end the AMQConnection threads does not run as a daemon thread what makes it hard to shutdown my tomcat properly.

Regards Claus

madness-inc commented 7 years ago

This should be resolved as of version 0.5.4?

jhalterman commented 7 years ago

@madness-inc Yep, somehow this issue was left open.