You create custom messaging service adapters when you want a functionality which the default adapter is not providing. Default messaging adapter (Action script adapter) shipped with BlazeDS will just broadcast the message, which the producer sends. What if you want change this functionality? You just have to create your own service adapters.
You can create custom service adapter class by extending the flex.messaging.services.ServiceAdapter class. Other classes which we will use are:
- flex.messaging.messages.AsyncMessage
- flex.messaging.messages.Message
- flex.messaging.services.MessageService
- flex.messaging.services.ServiceAdapter
MessageService class is used for sending message to all the clients subscribed to the destination. This class provides methods like pushMessageToClients(), using which we can send messages to all the subscribed clients.
AsyncMessage class is used for creating message to send to the users.
The ServiceAdapter class and other classes required are in the flex-messaging-common.jar and flex-messaging-core.jar files. These jar files are bundled with BlazeDS.
Sample application
I have created a simple application in which I am creating a message and sending it to all the clients subscribed to a destination. When the user clicks on a button reading “Ready to bid”, the application will send message to all the subscribed clients. I used custom adapter to modify the message and send it to all the clients.
Note: you can achieve this sample application without using custom adapter also
Creating sample application
Steps
1. Create a custom messaging adapter class
2. Add the adapter to the services-config.xml
3. Create a destination
4. Create Flex application to produce/consume the message
Create custom messaging adapter
In this class, I just modified the message body and sent it to all the clients. You have to override the invoke() method of the ServiceAdapter class. Invoke() method will be called when any client sends a message to the destination. By overriding the invoke() method you get access to the message object, which the client sent.
Download the custom messaging adapter’s Java file
Configure the services-config.xml and creating destination
You have to add your destination and adapter definitions to either services-config.xml or the messaging-config.xml file. Add the destination and the adapter as shown in the code snippet below. I have added the custom adapter, created above to the configuration file using the adapter element. I have also added the destination and mapped it to the adapter.
<service id=”message-service” class=”flex.messaging.services.MessageService”>
<adapters>
<adapter-definition id=”SujitAdapter” class=”com.adobe.adapter.CustomMessagingAdapter”/>
</adapters>
<destination id=”CustomMessagingAdapter”>
<adapter ref=”SujitAdapter”/>
</destination>
</service>
Create Flex application
We have completed the configuration and the development on the server. We will create a flex application which subscribe to the destination and receive messages from other users. Users can also send messages to other clients on click of a button.
That’s it. We have created a custom messaging adapter for BlazeDS. You can create your own messaging adapters and map your destinations to the adapters. There is lots more than just creating custom messaging adapters. You can even manage the list of clients subscribed to a destination yourself, instead of leaving it to BlazeDS
Adobe Rocks

March 14, 2008 at 11:25 am
It’s really easy to set up
Blazeds is the best idea of Adobe
March 14, 2008 at 11:39 am
Yes Tom, you are right … i Love LCDS and BlazeDS
They are awesome
Three Cheers to the product developers
March 22, 2008 at 4:51 pm
Interesting post. Thanks for the information. One question though – you’re just sending the intercepted message. What if you have a server-side event that triggers a need to push an unsolicited message. What properties of the message object need to be set (ex. do you need a message id? If so, how do you generate one?)? Thx.
March 25, 2008 at 4:01 am
How would you create a AIR application which uses Flex messaging?What configuration changes would I need to do?
March 25, 2008 at 5:11 am
Hi James,
I don’t think there are any specific configuration for AIR applications. You can use it as you were using it in a Flex web application. If you have any problem implementing, please let me know.
March 25, 2008 at 5:12 am
Hi Steven,
I am not sure what all are the properties which are to be set. I can try that and let you know.
Meanwhile if you find out, i will be glad to learn it from you.
April 8, 2008 at 5:11 pm
[...] FlexFactory et si l’on veut aller plus loin et gérer sont propre protocole c’est possible. Des exemples avec Spring et [...]
March 12, 2009 at 3:52 pm
hi
i have a one question ,how to implement the Producer and Consumer component using ‘BlazeDS Integration’ in DataBase valueobject insert.
if its possible or not???
March 26, 2009 at 7:28 pm
Hi Kutti kumar,
You want to notify all clients about a database operation, is that what you want? In that case, you can either use Data Management in LiveCycle Data Services or use messaging service of BlazeDS and write code to publish a message to all consumers when ever required.
Hope this helps.
May 5, 2009 at 7:07 pm
Thank you for this great work. All samples are clear.
However, I tried this sample but every time i execute it i have a message box saying “Send Failed”.
All my configuration files are fine.
I don’t know where the problem is
I can send you the project and thank you for any help
May 18, 2009 at 4:29 pm
Hi Oussamabk,
Please try recompiling you Flex application and also debug and check for more details in the FaultEvent object passed.
Hope this helps.
June 25, 2009 at 11:33 am
Hi Sujit,
Thanks alot for the article. I have a problem in the configuration.
I exactly followed your steps but when I start JBoss, I am getting NoClassDefFoundError(flex.messaging.services.ServiceAdaptor). All the required jar files are in the lib folder but still I am getting this error. I feel problem with class loading priority. Can you please provide a solution for this?
Thanks,
Rakesh Reddy Kaki
July 20, 2009 at 8:59 pm
Hi Rakesh,
Never encountered such problem, please let us know if you figured out why its not working. I am trying to see why this might be failing.
October 31, 2009 at 8:10 pm
hi nice work i have a doubt ..How can u route a message to a specific client based on it’s request
for example if there are 100 clients and a client tries to login then after login the info has to be routed only back to that client rite how can we do that