Announcement Announcement Module
Collapse
No announcement yet.
Per Vhost Connection Factory? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Per Vhost Connection Factory?

    I have a dynamic/arbitrary list of integration clients who I send messages to. I use Spring Integration for processing the messaging, and started using the very-promising recently released Spring AMQP M1 for handing off these messages to RabbitMQ.

    One of the requirements I have is that each client must not be able to see or interfere in anyway with the messages of other clients. Per the AMQP spec, the way to do this is by having a separate virtual host per client.

    From Spring Integration message processing side, this is easy. Each message arriving to the AMQP endpoint has 3 headers: virtual host, exchange name and routing key.

    The problem for me is that the AMQP endpoint (which I had initially implemented then later realized it is now available in SI 2 as well) operates on AmqpTemplate which is bound to a single connection. Per the AMQP spec, the vhost associated with a connection can't be changed once the connection has been established.

    To summarize all that, the vhost part in the messaging component of my application is dynamically set and can be different per each message. I'm not sure how could I implement the messaging solution using SI and Spring AMQP so that each message will use an AMQP connection that's bound to the vhost of the message being sent.

    I'm sharing this to get any insights and/or hints which would be greatly appreciated, and also to point Spring AMQP team to use cases which may be useful at this stage.

    P.S. Right now I'm using SI 1
    Last edited by AmrMostafa; Jul 31st, 2010, 11:09 AM.

  • #2
    My initial reaction is that this would require multiple ConnectionFactory instances, because that is where the connection parameters are set (username, password, virtual host). Considering that virtual host is a parameter for the connection itself, it really falls into a very different category than the exchange-name and routing-key. The virtual host is provided at the time that a Connection is established, and that Connection can be shared (across a number of threads) for the creation of multiple Channels (used by only one thread at a time). Only then do the 'exchange-name' and 'routing-key' enter the picture, simply as arguments of the publish operation.

    Therefore, we would probably need something analogous to the AbstractRoutingDataSource in Spring's JDBC support (see: http://static.springsource.org/sprin...ataSource.html). In this case, the "lookup key" could be the virtual-host name. The advantage of that approach is that the actual ConnectionFactory would still appear to be a single instance. It could be configured directly for a RabbitTemplate that is then shared by multiple client threads. Each would somehow establish the thread-bound context that includes the virtual-host (and perhaps this would need to apply more broadly including username, password, etc.).

    Does this make sense?

    By the way, I've just opened this issue for M2 so that at least we will provide a configuration option for virtual-host on the SingleConnectionFactory implementation: https://jira.springsource.org/browse/AMQP-34

    Comment


    • #3
      This makes a lot of sense, and it would be even better if such implementation would take into consideration that the list of vhosts maybe dynamically set and can't be declaratively defined (which is how targetDataSources are defined in AbstractRoutingDataSource).
      Last edited by AmrMostafa; Aug 1st, 2010, 01:37 PM.

      Comment


      • #4
        I've created this issue: https://jira.springsource.org/browse/AMQP-45

        Please vote for it.

        Thanks,
        Mark

        Comment


        • #5
          Awesome. Voted!

          Comment

          Working...
          X