stratos-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Lahiru Sandaruwan <lahi...@wso2.com>
Subject Re: [New Architecture] A Sample for Event Message Pub/Sub
Date Thu, 17 Oct 2013 12:11:25 GMT
Hi Nirmal,


On Thu, Oct 17, 2013 at 11:08 AM, Nirmal Fernando <nirmal070125@gmail.com>wrote:

>
>
>
> On Thu, Oct 17, 2013 at 10:20 AM, Lahiru Sandaruwan <lahirus@wso2.com>wrote:
>
>> Hi Imesh,
>>
>>
>> On Wed, Oct 16, 2013 at 10:56 AM, Imesh Gunaratne <imesh@apache.org>wrote:
>>
>>> Hi,
>>>
>>> Please find the below sample for publishing and receiving an event
>>> message using the new messaging system.
>>> *
>>> *
>>> *Publishing an Event Message*
>>>
>>> ...
>>> ServiceCreatedEvent event = new ServiceCreatedEvent();
>>> event.setServiceName("AppServer");
>>> TopologyEventMessage message = new TopologyEventMessage(event);
>>> publisher.sendMessage(message.getJson());
>>>
>>> *
>>> *
>>> *Receiving an Event Message*
>>>
>>> package org.apache.stratos.messaging.message;
>>>
>>> class MessageProcessor {
>>>     private Object jsonToObject(String json, Class type) {
>>>         ...
>>>     }
>>>
>>>     public EventMessageHeader readHeader(String json) {
>>>
>>
>> Are we reading header from Json message?
>> I thought we would use real message headers without looking at message at
>> all.
>>
>
> Can you send a sample on how to do that? Will that be supported by all
> message brokers?
>

We can set properties as follows,

        textMessage.setStringProperty(Constants.EVENT, eventName);

And retrieve as follows,

                String eventName =
textMessage.getStringProperty(Constants.EVENT);

I have changed the component with this. will commit soon.

Thanks.

>
>> Thanks.
>>
>>>         ...
>>>     }
>>> }
>>>
>>>
>>> class TopologyEventMessageProcessor extends MessageProcessor {
>>>     public void run() {
>>>         ...
>>>         String json = subscriber.receive();
>>>         // Read message header to identify the event, this will only
>>> parse the header
>>>         EventMessageHeader header = readHeader(json);
>>>
>>>         if
>>> (header.getEventClassName().equals(ServiceCreatedEvent.class.getName())) {
>>>             // Read the complete message and build the event
>>>             TopologyEventMessage message = jsonToObject(json,
>>> TopologyEventMessage.class);
>>>             ServiceCreatedEvent event = jsonToObject(message.getBody(),
>>> ServiceCreatedEvent.class);
>>>             ...
>>>         }
>>>     }
>>> }
>>>
>>> *jndi.properties File Content*
>>> connectionfactoryName=topicConnectionfactory
>>> connectionfactory.topicConnectionfactory=amqp://admin:admin@carbon
>>> /carbon?brokerlist='tcp://localhost:5677'
>>>
>>> java.naming.factory.initial=org.wso2.andes.jndi.PropertiesFileInitialContextFactory
>>>
>>>
>>> Thanks
>>> Imesh
>>>
>>
>>
>>
>> --
>> --
>> Lahiru Sandaruwan
>> Software Engineer,
>> Platform Technologies,
>> WSO2 Inc., http://wso2.com
>> lean.enterprise.middleware
>>
>> email: lahirus@wso2.com cell: (+94) 773 325 954
>> blog: http://lahiruwrites.blogspot.com/
>> twitter: http://twitter.com/lahirus
>> linked-in: http://lk.linkedin.com/pub/lahiru-sandaruwan/16/153/146
>>
>>
>
>
> --
> Best Regards,
> Nirmal
>
> Nirmal Fernando.
> PPMC Member & Committer of Apache Stratos,
> Senior Software Engineer, WSO2 Inc.
>
> Blog: http://nirmalfdo.blogspot.com/
>



-- 
--
Lahiru Sandaruwan
Software Engineer,
Platform Technologies,
WSO2 Inc., http://wso2.com
lean.enterprise.middleware

email: lahirus@wso2.com cell: (+94) 773 325 954
blog: http://lahiruwrites.blogspot.com/
twitter: http://twitter.com/lahirus
linked-in: http://lk.linkedin.com/pub/lahiru-sandaruwan/16/153/146

Mime
View raw message