问题
I've built the spring application using Spring Integration (defined in xml) to listen on a specific JMS Topic, transform the data and publish it RabbitMQ queue. In the xml all the configuration data (for example topic name, url, username, password) I externalized to the properties file, which i load in xml using this entry:
It's working just fine, but now it appeared that I need to create a webservice that the client can connect to and specify the topic name that he's interested in. The server would then pass back the reference of the queue to which it publishes the transformed messages. I thought it would be nice to reuse the currently working application. It would require then to load the new independent spring context each time the client sends the request and specify the properties at runtime not in the config.properties file.
Now the questions: 1. It seems to be positive that each client's request is treated in complete isolation, however isn't an overkill to start multiple contexts(each time client wants a new topic to be listened)? 2. How to pass the properties other way than a config file? Can I for example somehow pass a Map of parameters instead of the file when starting the context?
Many thanks for your suggestions.
回答1:
The dynamic-ftp sample shows how to fire up a context with properties.
For an inbound adapter you might need to make the context a child context - that way you can share the downstream flow across the users by sending to a common channel.
There are links in the readme for how to do that; the answer to this question and its followup show a similar technique when using Java @Configuration with email adapters.
来源:https://stackoverflow.com/questions/36472229/load-multiple-spring-instances-at-runtime