I have two service units - two servicemix beans. I am trying to send a
message from one su to another. The code is shown below:

I have created a message exchange factory in a postConstruct method
(init()). When this bean receives a message it should send another message
to the other bean, but when i try to set content (or comment out that line
and just try to send message) I get an exception thrown. I'm obviously doing
something wrong... Any help would be greatly appreciated.

        private MessageExchangeFactory messageExchangeFacory;
        
        private MessageExchange searchUsersMessageExchange;
         
        @Resource
        private ComponentContext context;
              
        @Resource
        private DeliveryChannel channel;
              
        @Operation(name = "search")
        public void myExchangeMethod(MessageExchange messageExchange) throws
MessagingException {
        if (messageExchange.getStatus() == ExchangeStatus.ACTIVE) {
                messageExchange.getMessage("in").setContent(new StringSource("No
users found"));
                //String searchTerm =
(String)((messageExchange.getMessage("in")).getProperty("searchTerm"));
                //Create message exchange for searching a store
                NormalizedMessage searchMessage =
searchUsersMessageExchange.createMessage();
                searchMessage.setContent(new StringSource("testing"));
                searchUsersMessageExchange.setMessage(searchMessage, "in");
                channel.send(searchUsersMessageExchange);

        
            NormalizedMessage message = messageExchange.getMessage("in");
            //StringSource content = (StringSource)message.getContent();
        
                        message.setContent(new StringSource("No Users found"));
                        messageExchange.setMessage(message, "out");
                        channel.send(messageExchange);
        }
        
            //log.info("myExchangeMethod() received exchange: " + 
messageExchange);
        }

              
        /**
        * @return the searchRequest
        */
        public Future<NormalizedMessage> getRequest1() {
                 return searchRequest;
        }
         
        @PostConstruct
        public void init() {
                if (searchService == null || context == null || channel == 
null) {
                   throw new IllegalStateException("Bean not initialized");
                }
                this.messageExchangeFacory = channel.createExchangeFactory(); 
                try {
                        searchUsersMessageExchange = 
messageExchangeFacory.createExchange(new
QName("endpoint:urn:mv40000:seminar:servicemix:store:endpoint"), new
QName("searchUsers"));
                } catch (MessagingException e) {
                        e.printStackTrace();
                }
        }
             
        @PreDestroy
        public void destroy() {
        }
              
        @Callback(condition="this.searchUsersMessageExchange.done")
        public NormalizedMessage answer() throws InterruptedException,
ExecutionException {
                System.out.println("answer from searchREquest");
                //NormalizedMessage answer1 = searchRequest.get();
            return null;
        }
-- 
View this message in context: 
http://www.nabble.com/Problem-with-sending-message-from-one-su-to-another-tp19612610p19612610.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Reply via email to