Results 1 to 2 of 2

Thread: Message destination

  1. #1
    Join Date
    Sep 2009
    Posts
    1

    Default 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. #2
    Join Date
    Apr 2005
    Location
    San Francisco, CA
    Posts
    1,224

    Default

    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.
    Jeremy Grelle

    Staff Engineer, Web Products Team
    SpringSource

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •