benningm / mtpolicyd

a modular policy daemon for postfix
21 stars 3 forks source link

2.01 Multiple Connections of same type #18

Closed LuckyFellow closed 8 years ago

LuckyFellow commented 8 years ago

it seems like it is not possible to have different connections of the same type. Though no error is issued but within plugins it is not possible to specify which connection to utilize.

Usecase is to have two different Redis instances. One is pure volatile the other is persistent with data written to disk.

Example "Connection" configuration:

<Connection redisVolatile>
  module = "Redis"
  servers = "127.0.0.1:6379"
</Connection>

<Connection redisPersistent>
  module = "Redis"
  servers = "127.0.0.1:6380"
</Connection>

When accessing a redis connection inside of a plugin, there is always the same connection returned. For example:

with 'Mail::MtPolicyd::Role::Connection' => {
  name => 'redisPersistent',
  type => 'Redis',
};

returns the same Redis connection as:

with 'Mail::MtPolicyd::Role::Connection' => {
  name => 'redisVolatile',
  type => 'Redis',
};

Though my expected result is that the corresponding, named connection redisPersistent is returned in the first example and redisVolatile in the second.

LuckyFellow commented 8 years ago

This issue was caused because of the wrong fix in Ticket #15. After applying the correct fix from Ticket #15, this issue resolved.

Maybe a warning would be useful if a connection is defined without servers so that default values are used.

benningm commented 8 years ago

The Role::Connection role will create a parameters with the "name" in the plugin.

If your plugin consumes the role:

with 'Mail::MtPolicyd::Role::Connection' => {
  name => 'myredis',
  type => 'Redis',
};

It will have a parameter myredis which defaults to "myredis" as value.

In your config you can set the myredis parameter to the connection you want to use for myredis:

<Plugin abc>
  module = "PluginAbc"
  myredis = "redisVolatile"
  # or
  # myredis = "redisPersistent"
</Plugin>