How to write a subscriber to read data from Broker..?

Hi All,

We are actually developing an adapter for IS and it uses broker for its listener notification mechanism.

The database server has an server extension which would publish the changes in the database to broker and somehow we need to subscribe it from our adapter.

we are planning to use Broker Client APIs

BrokerClient brokerClient = new BrokerClient(broker_host, broker_name, null,
client_group, “Publish Sample #1”, null);
BrokerEvent document = new BrokerEvent(brokerClient,“wm::is::testBroker::ListenerNotificationPublishDocument”);
document.setStringField(“Document”, “Yacht”);
brokerClient.publish(document);

This is the code i am juz checking locally to publish data to the document (ListenerNotificationPublishDocument) which is created as a result of my listener notification from our adapter…

I am aware that a trigger service is a subscriber by default to the broker and my trigger service works fine when i execute the above piece of code

but how to get that data from broker through code…?

Is that rite…? and how do i subscribe to the broker…?

Regards, Aravind

IMO, trying to get adapter code to subscribe to the Broker event is the wrong approach.

Typically, an adapter notification will detect a change in the resource (e.g. new row in a table) and will publish an event for others to subscribe to. What you seem to be planning is to have the DB extension publish an event, have the adapter receive it after which it will publish another event? What value would the adapter add in this case?

How the adapter detects the change in the resource varies by adapter. For the JDBC adapter, which I assume you’re mimicking to some degree, it uses a combination of DB triggers and polls a buffer table.

Of course you can have your do something different, including have the extension push the change out rather than waiting for a poll. Using the Broker seems fine, but not to go to the adapter. Just have it publish the doc for other components to subscribe.

Or, have the DB extension connect to your adapter via HTTP or sockets or whatever. Then have the adapter do the publish. This latter approach has the advantage of working even if no Broker is in place.

I think the sample adapter has demo code that does something like this but I’m not sure.

Hi Rob,

Sorry for such a long questionnaire… but i think iam pretty clear on my points… waiting for your feedback…

Polling
is where the IS queries the database for any changes in periodic intervals… (in our case, we r forming some polling queries which looks for some changes in our db and handling it)

Listener & Listener Notification is where the listener(listener created on IS through a connection object) object waitsforData from the server and then notifies the listener notifications associated with that particular listener…(am i rite…?)

I found the implementation code for Listener Notification in the WmSampleAdapter code package.

waitForData() method retrieves a connection object and calls a method receiveDocAllowTimeOut()… what role the time out plays here…?

I need to clarify my understanding as stated below…

Before configuring Broker

  1. When i create a listener notification in my developer… it creates a notification template and a notification document
    After configuring Broker
  2. When i create a listener notification in my developer… it creates a notification template and a notification document with publishable type and the broker doctype name (wm::is::test::listenernotifydoc)

2)Iam creating a flow service which just calls pub:savePipelineToFile and a trigger service in which this flow service and the notification document is associated

3)Now when i publish the document by adding some values to it… through the piece of code( 1st post)… the trigger is called automatically…and is creating the pipeline file with the values

When we publish it from our Server Extension
1)I need that brokerdoctype name (wm::is::test::listenernotifydoc) for publishing the changes. Is there any way i can get it…?

  1. Is there a possibility of not using the broker, so that i can directly publish the document to IS from my database server extension and the triggers can use it.

3)If the triggers consume the event when the document is published… wht should we do with waitForData() and supports() method…?

Regards, Aravind

You’re correct on the polling, listener and listener notification description.

The timeout in the sample is specific to the type of connection the sample adapter is using (sockets). You may not need such a mechanism.

The “When we publish it from our Server Extension” is where you are going astray. You do not do that. Your server extension should be interacting with your adapter listener. Your adapter waitForData() is waiting for data from your server extension. You can implement any number of ways to communicate between your server extension on your waitForData() call. The sample adapter uses sockets, which might be what you could do as well. Then the adapter, not the server extension, will publish the appropriate document. Your server extension talks to the adapter, not the Broker.

Hi Rob,

Thanks for guiding us towards the rite path… we made changes, so that our SXS talks to our adapter… (we have created an built-in adapter service which is called by the SXS to add the data into a queue)

In our waitForData() method… we make a call to check whether the queue has data and then return our document.

When it returns an object, the support method in our ListenerNotification is invoked… but runNotification() method is not called…

In WmSampleAdapter , the listener notification has runNotification(NotificationEvent ne)… i even checked with this one…

how do i make a call to doNotify() method…?

Regards, Aravind

“we have created an built-in adapter service which is called by the SXS to add the data into a queue”

Can you elaborate? What service where is being called? What is hosting the queue?

Is the supports() method of your class being called? Is it returning true?

Hi Rob,

The built-in service is just an adapter service(pub.xxx:addToQueue) which populates the queue(java.util)… it is being called by our SXS…

Yeah, support method is being called and it is returning true.

Regards, Aravind

I think I’ve contributed as much as I can. I’d need to dig into your adapter code in more detail to figure out what’s happening. Perhaps wM tech support can help?

Hi Rob,

Many thanks to you for your support… we got it working now.

Regards, Aravind