3 Replies Latest reply on Jul 15, 2010 5:08 AM by Mike Bauer

    Getting remote messaging to work with Java/Spring and Flex

    Mike Bauer

      I am trying to get remote messaging working on a Flex client with a Java/Spring backend.

       

      I have the channel is setup on the server as such:

      <

       

      channel-definition id="long-polling-channel"

       

       

      class="mx.messaging.channels.AMFChannel">

       

       

      <endpoint

       

       

      url="http://{server.name}:{server.port}/{context.root}/messagebroker/amflongpolling"

       

       

      class="flex.messaging.endpoints.AMFEndpoint" />

       

       

      <properties>

       

       

      <!-- Values for near-real time messaging -->

       

       

      <polling-enabled>true</polling-enabled>

       

       

      <polling-interval-millis>0</polling-interval-millis>

       

       

      <wait-interval-millis>-1</wait-interval-millis>

       

       

      <max-waiting-poll-requests>

      10

       

       

      </max-waiting-poll-requests>

       

       

      </properties>

       

       

      </channel-definition>

       

      In the Spring context, I am setting up the MessageBroker, MessageTemplate, and some custom wrapper code:

      <?

       

       

      xml version="1.0" encoding="UTF-8"?>

      <

       

      beans xmlns="http://www.springframework.org/schema/beans"

       

       

      xmlns:flex="http://www.springframework.org/schema/flex" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

       

       

      xsi:schemaLocation="

      http://www.springframework.org/schema/beans

      http://www.springframework.org/schema/beans/spring-beans-2.5.xsd

      http://www.springframework.org/schema/flex

      http://www.springframework.org/schema/flex/spring-flex-1.0.xsd"

       

      >

       

       

       

      <flex:message-broker id="messageServiceBroker" />

       

       

       

      <flex:message-destination id="event-bus"

       

       

      message-broker="messageServiceBroker" channels="long-polling-channel"

       

       

      message-time-to-live="1000"

       

       

      subscription-timeout-minutes="5"

       

       

      throttle-inbound-max-frequency="500" throttle-inbound-policy="ERROR"

       

       

      throttle-outbound-max-frequency="500" throttle-outbound-policy="IGNORE" />

       

       

       

      <bean id="defaultMessageTemplate" class="org.springframework.flex.messaging.MessageTemplate">

       

       

      <property name="defaultDestination" value="event-bus" />

       

       

      <property name="messageBroker" ref="messageServiceBroker" />

       

       

      </bean>

       

       

       

      <bean id="MessagingServices" class="com.bofa.esm.utility.messaging.MessagingServices">

       

       

      <property name="messageTemplate" ref="defaultMessageTemplate" />

       

       

      <property name="destinationName" value="event-bus" />

       

       

      <property name="scheduler" ref="PersistentQuartzScheduler" />

       

       

      </bean>

      </

       

      beans>

       

       

      The custom wrapper code is insignificant, but it basically creates a thread and posts a custom context over and over every minute.  The actual message is posted with this bit of code:

           messageTemplate.send(msgCtx);

       

      On the Flex side, I create a Channel and ChannelSet like thus:

      public

       

       

       

       

       

      static function getMessageChannelSet():ChannelSet{

       

      if(messageChannelSet == null){

      messageChannelSet =

      new ChannelSet();

       

       

      //e.g. 'http://{server.name}:{server.port}/{context.root}/messagebroker/amfpolling';

       

       

      var messageURL:String = getBaseUrl() + MESSAGE_URL;

       

      var channel:AMFChannel = new AMFChannel(MESSAGE_CHANNEL_NAME,messageURL);

      messageChannelSet.addChannel(channel);

      }

       

       

      return channelSet;

      }

       

      And then, latter I create a Consumer and add the channelset to it:

      var

       

       

       

       

       

      _messageConsumer:Consumer = new Consumer();

       

      var msgChannel:ChannelSet = RemotingUtility.getMessageChannelSet();

       

       

      var encrypted:Object = this.encrypt(_sessionModel.username, _sessionModel.password);

       

      var token:AsyncToken = msgChannel.login(encrypted.userId, encrypted.password);

       

      _messageConsumer.channelSet = msgChannel;

      _messageConsumer.destination =

      "event-bus";

      _messageConsumer.addEventListener(MessageEvent.RESULT,

      this.onMessage);

       

      The problem is, I dont get the messages from the server.  In fact, from what I can tell by the logs when I post a message from the server, it doesn't appear that anything is listening to the channel:

      09:32:03,106 INFO [MessagingServices] Posting message...

      09:32:08,184 INFO [STDOUT] [BlazeDS]Before invoke service: message-service

      incomingMessage: Flex Message (flex.messaging.messages.AsyncMessage)

      clientId = CC2B0D5D-B00A-CD8B-CE43-0430C8CC10DF

      correlationId = null

      destination = event-bus

      messageId = CC3211B4-F80E-15FE-076C-00C963ED5D01

      timestamp = 1278595928184

      timeToLive = 0

      body = com.bofa.esm.utility.messaging.SimpleMessageContext@159a771

      09:32:08,200 INFO [STDOUT] [BlazeDS]Before invoke service: message-service

      incomingMessage: Flex Message (flex.messaging.messages.AsyncMessage)

      clientId = CC2B0D5D-B00A-CD8B-CE43-0430C8CC10DF

      correlationId = null

      destination = event-bus

      messageId = CC3211B4-F80E-15FE-076C-00C963ED5D01

      timestamp = 1278595928184

      timeToLive = 0

      body = com.bofa.esm.utility.messaging.SimpleMessageContext@159a771

      09:32:08,200 INFO [STDOUT] [BlazeDS]Sending message: Flex Message (flex.messaging.messages.AsyncMessage)

      clientId = CC2B0D5D-B00A-CD8B-CE43-0430C8CC10DF

      correlationId = null

      destination = event-bus

      messageId = CC3211B4-F80E-15FE-076C-00C963ED5D01

      timestamp = 1278595928184

      timeToLive = 1000

      body = com.bofa.esm.utility.messaging.SimpleMessageContext@159a771

      to subscribed clientIds: []

      09:32:08,200 INFO [STDOUT] [BlazeDS]Sending message: Flex Message (flex.messaging.messages.AsyncMessage)

      clientId = CC2B0D5D-B00A-CD8B-CE43-0430C8CC10DF

      correlationId = null

      destination = event-bus

      messageId = CC3211B4-F80E-15FE-076C-00C963ED5D01

      timestamp = 1278595928184

      timeToLive = 1000

      body = com.bofa.esm.utility.messaging.SimpleMessageContext@159a771

      to subscribed clientIds: []

      09:32:08,200 INFO [STDOUT] [BlazeDS]After invoke service: message-service; execution time = 0ms

      09:32:08,200 INFO [STDOUT] [BlazeDS]After invoke service: message-service; execution time = 0ms

      09:32:08,200 INFO [STDOUT] [BlazeDS]After invoke service: message-service

      reply: null

      09:32:08,200 INFO [STDOUT] [BlazeDS]After invoke service: message-service

      reply: null

      09:32:12,075 INFO [STDOUT] [BlazeDS]Before invoke service: message-service

      incomingMessage: Flex Message (flex.messaging.messages.AsyncMessage)

      clientId = CC2B0D5D-B00A-CD8B-CE43-0430C8CC10DF

      correlationId = null

      destination = event-bus

      messageId = CC3236D0-7B0D-182C-5632-C84FB4D1E215

      timestamp = 1278595932075

      timeToLive = 0

      body = com.bofa.esm.utility.messaging.SimpleMessageContext@1a6595b

      09:32:12,075 INFO [STDOUT] [BlazeDS]Before invoke service: message-service

      incomingMessage: Flex Message (flex.messaging.messages.AsyncMessage)

      clientId = CC2B0D5D-B00A-CD8B-CE43-0430C8CC10DF

      correlationId = null

      destination = event-bus

      messageId = CC3236D0-7B0D-182C-5632-C84FB4D1E215

      timestamp = 1278595932075

      timeToLive = 0

      body = com.bofa.esm.utility.messaging.SimpleMessageContext@1a6595b

      09:32:12,075 INFO [STDOUT] [BlazeDS]Sending message: Flex Message (flex.messaging.messages.AsyncMessage)

      clientId = CC2B0D5D-B00A-CD8B-CE43-0430C8CC10DF

      correlationId = null

      destination = event-bus

      messageId = CC3236D0-7B0D-182C-5632-C84FB4D1E215

      timestamp = 1278595932075

      timeToLive = 1000

      body = com.bofa.esm.utility.messaging.SimpleMessageContext@1a6595b

      to subscribed clientIds: []

      09:32:12,075 INFO [STDOUT] [BlazeDS]Sending message: Flex Message (flex.messaging.messages.AsyncMessage)

      clientId = CC2B0D5D-B00A-CD8B-CE43-0430C8CC10DF

      correlationId = null

      destination = event-bus

      messageId = CC3236D0-7B0D-182C-5632-C84FB4D1E215

      timestamp = 1278595932075

      timeToLive = 1000

      body = com.bofa.esm.utility.messaging.SimpleMessageContext@1a6595b

      to subscribed clientIds: []

      09:32:12,075 INFO [STDOUT] [BlazeDS]After invoke service: message-service; execution time = 0ms

      09:32:12,075 INFO [STDOUT] [BlazeDS]After invoke service: message-service; execution time = 0ms

      09:32:12,075 INFO [STDOUT] [BlazeDS]After invoke service: message-service

      reply: null

      09:32:12,075 INFO [STDOUT] [BlazeDS]After invoke service: message-service

      reply: null

       

      Shouldn't the "subscribed clientIds: []" have something listed as subscribed?  What am I missing?

        • 3. Re: Getting remote messaging to work with Java/Spring and Flex
          Mike Bauer Level 1

          I made some modifications to the code section that registers the Consumer:

           

            Alert.show(

          "onRegister running","AppShellMediator",Alert.OK);

           

            var _messageConsumer:Consumer = new Consumer();

           

            var msgChannel:ChannelSet = RemotingUtility.getMessageChannelSet();

            _messageConsumer.channelSet = msgChannel;

            _messageConsumer.destination =

          "event-bus";

            _messageConsumer.addEventListener(MessageEvent.RESULT,

          this.onMessage);

            _messageConsumer.subscribe(

          "MessagingClient"+Math.random());

           

          if(_messageConsumer.connected)

                Alert.show(

          "Message Channel is connected","AppShellMediator",Alert.OK);

           

            if(_messageConsumer.authenticated)

                Alert.show(

          "Message Channel is authenticated","AppShellMediator",Alert.OK);

           

            if(_messageConsumer.subscribed)

                Alert.show(

          "Message Channel is subscribed, clientId: "+_messageConsumer.clientId,"AppShellMediator",Alert.OK);

           

          I am now calling the subscribe method, then testing to see if the consumer is connected, authorized, and subscribed.  The first two return True, the last one does not.  So, despite the call to subscribe(), the Consumer is not subscribed.  Is there a way to figure out why?  Possibly there was an error somewhere?