0
votes

I'm working on abstracting out any sort of messaging framework for some code I'm working on. Basically, I'm using a combination of Spring AOP and Spring Integration to generate messages without the Java code knowing anything about RabbitMQ, JMS, or even Spring Integration. That said, what I'm using to generate the messages is contained in its own .jar, and it re-used by several other areas of the application. I currently have the messaging system set up such that the channels on which messages are sent are specified by the code that calls the system (i.e., channels are generated automatically based on the external method invocation) by specifying the channel name in the message header and using a header-value router to create the channels if they don't exist. My issue comes in on the endpoint of these channels - the intention of the current structure is to allow Spring to change to any messaging structure as requirements specify or change. I know how to take a static channel and use outbound channel converters/gateways to send it to a pre-specified RabbitMQ/JMS queue and process from there; what I'm struggling with is how to tell Spring that I need every channel created by the router to have a RabbitMQ (or whatever other messaging system gets implemented) outbound channel adapter that's dynamically generated based on the channel name since we don't know channel names beforehand.

Is this possible? And if not, would you mind providing input as to what could perhaps be a better way?

Thanks ahead of time!

Here's a basic template of what my config file looks like - I have an initial channel ("messageChannel") which gets sent to a publish-subscribe-channel and queuing channel depending on one of the message headers and is routed from there.

<!--Header value based channel configurations-->
<int:channel id="messageChannel" />
<int:channel id="queue" />
<int:publish-subscribe-channel id="topic" />

<!--Header-based router to route to queue or topic channels-->
<int:header-value-router input-channel="messageChannel"
                         header-name="#{ T(some.class.with.StringConstants).CHANNEL_TYPE}" />   

<!--Re-routes messages according to their destination and messaging type-->
<int:header-value-router input-channel="queue"
                         header-name="#{ T(some.class.with.StringConstants).MESSAGE_DESTINATION}" />

<int:header-value-router input-channel="topic"
                         header-name="#{ T(some.class.with.StringConstants).MESSAGE_DESTINATION}" />

<!--AOP configuration - picks up on any invocation of some.class.which.generates.Messages.generateMessage()
from a Spring-managed context.-->
<aop:config>
    <aop:pointcut id="eventPointcut"
                  expression="execution(* some.class.which.generates.Messages.generateMessage(..))" />

    <aop:advisor advice-ref="interceptor" pointcut-ref="eventPointcut"/>
</aop:config>

<int:publishing-interceptor id="interceptor" default-channel="messageChannel">
    <int:method pattern="generateMessage" payload="#return" channel="messageChannel" />
</int:publishing-interceptor>
1

1 Answers

0
votes

See the dynamic-ftp sample; it uses a dynamic router that creates new outbound endpoints/channels on demand.