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 <[email protected]> wrote:

> Hi,
>
> Please check my comments inline.
>
> 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");
>> 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
>

Reply via email to