Announcement Announcement Module
Collapse
No announcement yet.
Message destination Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Message destination

    Right now I'm creating it form my web-application-config.xml by defining <flex:jms-message-destination />. I'm wondering is there any way to create flex message destination dynamically from java class. Thanks.

  • #2
    Sure, it's possible. All you really need is a reference to the MessageBroker (which you could have injected by Spring), then you can use its API to create the destination. For example:

    Code:
    @Component
    public class DynamicDestinationExample {
        
        private final MessageBroker broker;
        
        @Autowired
        public DynamicDestinationExample(MessageBroker broker) {
            this.broker = broker;
        }
        
        public void createMessageDestination(String id) {
            MessageService service = (MessageService) broker.getServiceByType(MessageService.class.getName());
            MessageDestination dest = (MessageDestination) service.createDestination(id);
    
            //... set properties on the destination and initialize its adapter ...
    
            dest.start();
        }
    }
    The thing that's a bit tricky is getting everything initialized correctly, especially if you want the destination to be backed by JMS because you have the additional burden of configuring and setting the JmsAdapter at runtime.

    I'd suggest taking a look at the source of MessageDestinationFactory to see what all is required. You might even consider setting up and invoking an instance of MessageDestinationFactory directly from your code and overriding its configureAdapter() method to programmatically set up the JmsAdapter.

    Comment

    Working...
    X