+1

On Thu, Oct 17, 2013 at 11:29 AM, Nirmal Fernando <[email protected]>wrote:

> Hi Imesh,
>
>
> On Wed, Oct 16, 2013 at 10:56 AM, Imesh Gunaratne <[email protected]>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");
>>
>
> It is better to mandate the service name, by populating this via
> constructor. IMO we should do likewise to other events too.
>
> 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) {
>>         ...
>>     }
>> }
>>
>>
>> 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);
>>             ...
>>         }
>>     }
>> }
>>
>
> Imesh, I don't think this is a good OOP practice. In this scenario, I
> think we should follow the 'chain of responsibility' design pattern.
>
> I'll give a try to fix this.
>
>>
>> *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
>>
>
>
>
> --
> Best Regards,
> Nirmal
>
> Nirmal Fernando.
> PPMC Member & Committer of Apache Stratos,
> Senior Software Engineer, WSO2 Inc.
>
> Blog: http://nirmalfdo.blogspot.com/
>



-- 
*Imesh Gunaratne*
Technical Lead
WSO2 Inc: http://wso2.com
T: +94 11 214 5345 M: +94 77 374 2057
W: http://imesh.gunaratne.org
Lean . Enterprise . Middleware

Reply via email to