PDA

View Full Version : Own Adapter for Flex Messaging



Mayday171
Jun 4th, 2009, 07:43 AM
Hey Guys,

There is a problem and I hope that you can help me :-).

I have coded an Adapter for flex messaging:


public class FlexDeviceDataListener extends ServiceAdapter implements DeviceDataListener {

private String data = "Test";

public void newDataReceived(String deviceId) {
/*MessageBroker msgBroker = MessageBroker.getMessageBroker(null);
String clientID = UUIDUtils.createUUID();
// creating a new async message.

AsyncMessage msg = new AsyncMessage();
// setting the destination for this message.

msg.setDestination("DataPush");
msg.setClientId(clientID);
msg.setMessageId(UUIDUtils.createUUID());
msg.setBody(deviceId);
msg.setHeader("topic", "flex.messaging.unknownData");
msgBroker.routeMessageToService(msg, null);*/
}
}

I have declared it in the spring config like this:


<bean id="dataPushAdapter" class="org.springframework.flex.core.ManageableComponentF actoryBean">
<constructor-arg value="rm.proemion.ui.flex.commons.FlexDeviceDataListener"/>
</bean>

And for the message-destination I hav added this:


<flex:message-destination id="dataPush" channels="my-streaming-amf,my-polling-amf"
service-adapter="dataPushAdapter"/>

Now the problem ;-):

If the server gets new data the newDataReceived method in the FlexDeviceDataListener class will trigger. This java method should route the message to the flex client which is subscribed. The problem is that the messageBroker that I want to get to route the message ist null. Its throws a NullPointerException everytime it try to get the messageBroker instance.

What goes wrong there??
Do I have to declare an extra MessageBroker in spring config ??

THX

Mayday171
Jun 4th, 2009, 08:00 AM
I have solved the problem:

In the flex.messages.MessageBroker Class the method getMessageBroker(String id) required a default messageBroker id. If you call getMessageBroker(null) the inbuild default MessageBroker id is "__default__", but with blazeds spring integration it is _messageBroker. So you have to call getMessageBroker("_messageBroker")

Mark Fisher
Jun 4th, 2009, 06:45 PM
You might prefer to use a constant for that. If so, you can use this:


org.springframework.flex.config.BeanIds.MESSAGE_BR OKER