You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@stratos.apache.org by Imesh Gunaratne <im...@apache.org> on 2013/10/16 07:26:02 UTC

[New Architecture] A Sample for Event Message Pub/Sub

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) {
        ...
    }
}


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

Re: [New Architecture] A Sample for Event Message Pub/Sub

Posted by Imesh Gunaratne <im...@apache.org>.
Hi Isuru,

I'm sorry I think I have mentioned it as private in the mail but in the
file in git it is public. May be we could change it to protected.

Thanks
Imesh


On Wed, Oct 16, 2013 at 11:12 PM, Isuru Haththotuwa <is...@wso2.com> wrote:

> Hi Imesh,
>
> On Wed, Oct 16, 2013 at 10:56 AM, Imesh Gunaratne <im...@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) {
>>         ...
>>     }
>> }
>>
>>
>> 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);
>>             ...
>>         }
>>     }
>> }
>>
>
> In the MessageProcessor class, the method jsonToObject(String json, Class
> type) is marked as private, and you seem to have used another method with
> the same signature it in the TopologyEventMessageProcessor class. Is this
> method intentionally not exposed via the MessageProcessor class? Maybe we
> could make it protected so that it can be overridden at a concrete
> MessageProcessor 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
>>
>
>
>
> --
> Thanks and Regards,
>
> Isuru H.
> Software Engineer, WSO2 Inc.
> +94 716 358 048* <http://wso2.com/>*
>
>
>

Re: [New Architecture] A Sample for Event Message Pub/Sub

Posted by Isuru Haththotuwa <is...@wso2.com>.
Hi Imesh,

On Wed, Oct 16, 2013 at 10:56 AM, Imesh Gunaratne <im...@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) {
>         ...
>     }
> }
>
>
> 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);
>             ...
>         }
>     }
> }
>

In the MessageProcessor class, the method jsonToObject(String json, Class
type) is marked as private, and you seem to have used another method with
the same signature it in the TopologyEventMessageProcessor class. Is this
method intentionally not exposed via the MessageProcessor class? Maybe we
could make it protected so that it can be overridden at a concrete
MessageProcessor 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
>



-- 
Thanks and Regards,

Isuru H.
Software Engineer, WSO2 Inc.
+94 716 358 048* <http://wso2.com/>*

Re: [New Architecture] A Sample for Event Message Pub/Sub

Posted by Nirmal Fernando <ni...@gmail.com>.
Seems like we can: http://nullege.com/codes/search/txamqp.content.Content


On Thu, Oct 17, 2013 at 5:58 PM, Nirmal Fernando <ni...@gmail.com>wrote:

> Lahiru,
>
> This complicates the stuff a bit though.
>
> * You need to pass headers separately to TopicPublisher, in a generic
> manner.
> * and we should get confirmed that we can set headers via Python library.
>
>
> On Thu, Oct 17, 2013 at 5:41 PM, Lahiru Sandaruwan <la...@wso2.com>wrote:
>
>> 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 <la...@wso2.com>wrote:
>>>
>>>> Hi Imesh,
>>>>
>>>>
>>>> On Wed, Oct 16, 2013 at 10:56 AM, Imesh Gunaratne <im...@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
>>
>>
>
>
> --
> Best Regards,
> Nirmal
>
> Nirmal Fernando.
> PPMC Member & Committer of Apache Stratos,
> Senior Software Engineer, WSO2 Inc.
>
> Blog: http://nirmalfdo.blogspot.com/
>



-- 
Best Regards,
Nirmal

Nirmal Fernando.
PPMC Member & Committer of Apache Stratos,
Senior Software Engineer, WSO2 Inc.

Blog: http://nirmalfdo.blogspot.com/

Re: [New Architecture] A Sample for Event Message Pub/Sub

Posted by Nirmal Fernando <ni...@gmail.com>.
Lahiru,

This complicates the stuff a bit though.

* You need to pass headers separately to TopicPublisher, in a generic
manner.
* and we should get confirmed that we can set headers via Python library.


On Thu, Oct 17, 2013 at 5:41 PM, Lahiru Sandaruwan <la...@wso2.com> wrote:

> Hi Nirmal,
>
>
> On Thu, Oct 17, 2013 at 11:08 AM, Nirmal Fernando <ni...@gmail.com>wrote:
>
>>
>>
>>
>> On Thu, Oct 17, 2013 at 10:20 AM, Lahiru Sandaruwan <la...@wso2.com>wrote:
>>
>>> Hi Imesh,
>>>
>>>
>>> On Wed, Oct 16, 2013 at 10:56 AM, Imesh Gunaratne <im...@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
>
>


-- 
Best Regards,
Nirmal

Nirmal Fernando.
PPMC Member & Committer of Apache Stratos,
Senior Software Engineer, WSO2 Inc.

Blog: http://nirmalfdo.blogspot.com/

Re: [New Architecture] A Sample for Event Message Pub/Sub

Posted by Lahiru Sandaruwan <la...@wso2.com>.
Hi Nirmal,


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

>
>
>
> On Thu, Oct 17, 2013 at 10:20 AM, Lahiru Sandaruwan <la...@wso2.com>wrote:
>
>> Hi Imesh,
>>
>>
>> On Wed, Oct 16, 2013 at 10:56 AM, Imesh Gunaratne <im...@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

Re: [New Architecture] A Sample for Event Message Pub/Sub

Posted by Nirmal Fernando <ni...@gmail.com>.
On Thu, Oct 17, 2013 at 10:20 AM, Lahiru Sandaruwan <la...@wso2.com>wrote:

> Hi Imesh,
>
>
> On Wed, Oct 16, 2013 at 10:56 AM, Imesh Gunaratne <im...@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?

>
> 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/

Re: [New Architecture] A Sample for Event Message Pub/Sub

Posted by Lahiru Sandaruwan <la...@wso2.com>.
Hi Imesh,


On Wed, Oct 16, 2013 at 10:56 AM, Imesh Gunaratne <im...@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.

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

Re: [New Architecture] A Sample for Event Message Pub/Sub

Posted by Reka Thirunavukkarasu <re...@wso2.com>.
Thanks Imesh. +1. Will follow it up in the relevant places to create the
pub/sub model.

Thanks,
Reka

On Wed, Oct 16, 2013 at 10:56 AM, Imesh Gunaratne <im...@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) {
>         ...
>     }
> }
>
>
> 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



-- 
Reka Thirunavukkarasu
Software Engineer,
WSO2, Inc.:http://wso2.com,
Mobile: +94776442007

Re: [New Architecture] A Sample for Event Message Pub/Sub

Posted by Imesh Gunaratne <im...@wso2.com>.
+1


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

> Hi Imesh,
>
>
> On Wed, Oct 16, 2013 at 10:56 AM, Imesh Gunaratne <im...@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");
>>
>
> 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

Re: [New Architecture] A Sample for Event Message Pub/Sub

Posted by Nirmal Fernando <ni...@gmail.com>.
Hi Imesh,


On Wed, Oct 16, 2013 at 10:56 AM, Imesh Gunaratne <im...@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");
>

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/

Re: [New Architecture] A Sample for Event Message Pub/Sub

Posted by Imesh Gunaratne <im...@apache.org>.
Hi Isuru,

Sorry about that, publisher could be created as follows:

import org.apache.stratos.messaging.broker.publish.TopicPublisher;
...
TopicPublisher publisher = new TopicPublisher("topology-topic");


That's a great thought. I will create another method overload for the above
functionality.
...
ServiceCreatedEvent event = new ServiceCreatedEvent();
event.setServiceName("AppServer");
TopologyEventMessage message = new TopologyEventMessage(event);
publisher.publish(message); // Actually the method name is publish not
sendMessage


Yes we could do below:
private Event jsonToObject(String json, Class type)

Thanks for the suggestions!

Best Regards,
Imesh



On Wed, Oct 16, 2013 at 3:37 PM, Isuru Perera <is...@wso2.com> wrote:

> Hi,
>
> Please check my comments inline.
>
> On Wed, Oct 16, 2013 at 10:56 AM, Imesh Gunaratne <im...@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());
>>
> How do we get the publisher here. :)
>
> And we should be able to get the json inside publisher, right? Otherwise
> everyone will have to call getJson() before calling sendMessage(). Also
> TopologyEventMessage class seems to be a *final* class, hence I do not see
> any problem of calling getJson() inside publisher.
>
>>
>> *
>> *
>> *Receiving an Event Message*
>>
>> package org.apache.stratos.messaging.message;
>>
>> class MessageProcessor {
>>     private Object jsonToObject(String json, Class type) {
>>
> This could return a generic Event type. Implies that when looking at below
> code.
>
>>         ...
>>     }
>>
>>     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);
>>             ...
>>         }
>>     }
>> }
>>
>> *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
>>
>
>
>
> --
> Isuru Perera
> Senior Software Engineer | WSO2, Inc. | http://wso2.com/
> Lean . Enterprise . Middleware
>
> about.me/chrishantha
>

Re: [New Architecture] A Sample for Event Message Pub/Sub

Posted by Isuru Perera <is...@wso2.com>.
Hi,

Please check my comments inline.

On Wed, Oct 16, 2013 at 10:56 AM, Imesh Gunaratne <im...@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());
>
How do we get the publisher here. :)

And we should be able to get the json inside publisher, right? Otherwise
everyone will have to call getJson() before calling sendMessage(). Also
TopologyEventMessage class seems to be a *final* class, hence I do not see
any problem of calling getJson() inside publisher.

>
> *
> *
> *Receiving an Event Message*
>
> package org.apache.stratos.messaging.message;
>
> class MessageProcessor {
>     private Object jsonToObject(String json, Class type) {
>
This could return a generic Event type. Implies that when looking at below
code.

>         ...
>     }
>
>     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);
>             ...
>         }
>     }
> }
>
> *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
>



-- 
Isuru Perera
Senior Software Engineer | WSO2, Inc. | http://wso2.com/
Lean . Enterprise . Middleware

about.me/chrishantha