Found an answer to this from the reference manual:
" If you add the WSN NotificationProducer capability to your
resource type, it will automatically send out WSRP change
notifications every time the WSRP SetResourceProperties operation is
used to modify a property. It also creates a WSN topic for each
resource property so that clients can subscribe to notifications
about individual properties, with the topic name being equal to the
property name. In other words, for changes made via WSRP, you don't
have to do anything!"
What happens is that when I update MyParameter, the frameworks sends
by default WSRP change notifications using topic name equal to the
property name. This is why the event topic I get using
message.getTopic() is
http://ws.example.com/muse/test/notification}MyParameter.
What I cannot understand is why I cannot send notification explicitly
from my setMyParameter method as shown in the code I wrote. The
consumer should receive both notification (one is the 'default' WSRP
change notification -topic=MyParameter- and one is my explicit
notification -topic=MyTopic-).
The consumer does not even receive the latter one (I print in a file
every message I receive in my accept() method).
2007/4/17, Marco Parmiani <[EMAIL PROTECTED]>:
I probably used some inappropriate words, but I understood that the producer
'sends' events to the subscribers, and that publisher and subscribers are on
separate processes (so no exception catch mechanism, sorry again for that).
I'll try to be more clear.
My problem it's at the point 3: in my Producer, in a method setMyParameter, I
use wsn.publish(_TOPIC_NAME, payload), where _TOPIC_NAME is MyTopic (excluding
prefix and namespace).
My Consumer subscribes to the Producer with producer.subscribe(consumer, null,
null); (all events sent to the consumer).
Within the Consumer I want to process only events sent with topic "MyTopic" (in this
simple example it's not very useful since every event generated in Producer should be of topic
"MyTopic", but it's just for test) and therefore I write in my accept():
public boolean accepts(NotificationMessage message)
{
// should accept only messages whose topic is MyTopic
QName tn = message.getTopic();
return topicname.equals(tn);
}
If I print message.getTopic() I get:
http://ws.example.com/muse/test/notification}MyParameter (? the events
generated in the Producer should use MyTopic see the code in my first post) and
the equal returns false (because topicname is previously set to
topicname = new QName(NAMESPACE_URI, "MyTopic", PREFIX);
Could you tell me if I understood the mechanism now or if I misunderstood
again?
Thanks,
Marco
2007/4/17, Daniel Jemiolo <[EMAIL PROTECTED] >:
> I think you're confusing the potential exceptions thrown by the publish()
> method with the way events are published to consumers. When you say the
> events are "thrown", that makes me think of how the exceptions are thrown
> (if there's an error), but that happens on the producer side and won't be
> seen by a consumer. If you want to receive messages from a consumer, you
> need to:
>
> 1. create a subscription using NotificationProducerClient.subscribe(),
> where the EPR you provide is the EPR of the consumer
>
> 2. add the NotificationConsumer capability to your consumer resource (add
> the Notify operation to your WSDL)
>
> 3. create a NotificationMessageListener that returns 'true' in accepts()
> if the current message has your topic.
>
> All of this should work when producer and consumer are in two completely
> separate processes, and there is no way for a consumer to "catch" anything
> from the call to publish().
>
> Dan
>
>
>
> "Marco Parmiani" <[EMAIL PROTECTED]> wrote on 04/16/2007 02:38:06
> PM:
>
> > Thanks for the reply.
> > However the use of the 'old' topic is intentional: what I'd like to do
> is
> > to throw events in the MyTopic topic from within the setMyParameter
> method.
> > Therefore I call:
> >
> > public void setMyParameter(int param0) {
> > _MyParameter = param0;
> > QName messageName = new QName(NAMESPACE_URI, "MyParameterUpdate",
> PREFIX);
> > Element payload = XmlUtils.createElement(messageName, "MyParameter has
> been
> > updated.");
> > wsn.publish(_TOPIC_NAME, payload);
> > }
> >
> > I really can't understand why if I call message.getTopic() from a
> consumer
> > application, I get
> >
> {http://ws.example.com/muse/test/notification}MyParameter< http://ws.example.
> > com/muse/test/notification%7DMyParameter>(I
> > expected MyTopic or eventually MyParameterUpdate,
> > but not MyParameter that is the name of the property).
> >
> > The thing is shown here: (from:
> >
>
http://ws.apache.org/muse/docs/2.0.0/manual/how-to/publish-any-notification.html
> > )
> >
> > // you can add topics programmatically or via RMD document
> > //
> > QName topicName = new QName("http://example.com/server-product",
> > "ServerUpdates");
> > wsn.addTopic(topicName);
> >
> > //
> > // you can later publish messages to the topic
> > //
> > QName messageName = new QName("http://example.com/server-product",
> > "UpdateMessage");
> > String updateMessage = "Something important happened!";
> > Element payload = XmlUtils.createElement(messageName, updateMessage);
> >
> > wsn.publish(topicName, payload);
> >
> > The code publishes a message ('UpdateMessage) with description
> ("Something
> > important happened") to a previously defined Topic. That is exactly what
> I'm
> > trying to do. And I expect that a consumer application catches and
> processes
> > these events if I write into the accept() method:
> >
> > QName topicName = new QName("http://example.com/server-product",
> > "ServerUpdates");
> > QName tn = message.getTopic();
> > return topicName.equals(tn);
> >
> > This method should return TRUE if events generated with the code above,
> but
> > in my case does not.
> > Am I understanding correctly the use of topics and subscriptions?
> >
> > Thanks in advance,
> > Marco
> >
> > 2007/4/16, [EMAIL PROTECTED] <[EMAIL PROTECTED]>:
> > >
> > > I believe that you setup for your NotificationProducer in your
> "Runtime"
> > > event is the part causing you the problem.
> > >
> > > The code below should help, as far as I see it your still publishing
> > > with your old topic [wsn.publish(_TOPIC_NAME, payload);]
> > >
> > >
> > >
> > > QName messageName = new QName(NAMESPACE_URI, "MyParameterUpdate",
> > > PREFIX);
> > > Wsn.addTopic(messageName);
> > > Element payload = XmlUtils.createElement(messageName, "MyParameter has
> > > been
> > > updated.");
> > > try {
> > > wsn.publish (messageName, payload);
> > > } catch (Throwable error) {
> > > error.printStackTrace();
> > > }
> > >
> > >
> > > /Lenni
> > >
> > > -----Original Message-----
> > > From: Marco Parmiani [mailto: [EMAIL PROTECTED]
> > > Sent: 16 April 2007 15:50
> > > To: [email protected]
> > > Subject: Regarding Muse Topics and subscriptions
> > >
> > > Hello, I'm quite new to Muse and I'd like to better understand the
> > > Topics
> > > mechanism.
> > >
> > > This is what I've done:
> > > I took the wsdl included in wsn-producer example (added a new
> parameter,
> > > called MyParameter), followed the tutorial on the site and generated
> > > correctly the classes (and the war file).
> > > For the Topic name I specified:
> > > // NAMESPACE_URI = " http://ws.example.com/muse/test/notification",
> > > PREFIX
> > > ="tns"
> > > private static final QName _TOPIC_NAME = new QName(NAMESPACE_URI,
> > > "MyTopic",
> > > PREFIX);
> > >
> > > and into initializeCompleted() I added:
> > >
> > > wsn =
> > > (NotificationProducer)res.getCapability(WsnConstants.PRODUCER_URI );
> > > wsn.addTopic(_TOPIC_NAME);
> > >
> > > In setMyParameter(int param0) method I added the code for 'throwing'
> new
> > > events:
> > >
> > > QName messageName = new QName(NAMESPACE_URI, "MyParameterUpdate",
> > > PREFIX);
> > > Element payload = XmlUtils.createElement(messageName, "MyParameter has
> > > been
> > > updated.");
> > > try {
> > > wsn.publish(_TOPIC_NAME, payload);
> > > } catch (Throwable error) {
> > > error.printStackTrace();
> > > }
> > >
> > > Now, from what I understand that code will throw new events on the
> Topic
> > > named MyTopic. These events are messages named MyParameterUpdate and
> > > they
> > > include my description "MyParameter has been updated".
> > > The problem is that when I use the wsn-consumer (a little bit
> > > customized) I
> > > do not get the result I expect:
> > >
> > > ConsumerCapabilityImpl.java:
> > > // ...imports and class def
> > > private QName topicname = null;
> > > String PREFIX = "tns";
> > > String NAMESPACE_URI = " http://ws.example.com/muse/test/notification";
> > > public void initializeCompleted()
> > > throws SoapFault
> > > {
> > > super.initializeCompleted();
> > >
> > > topicname = new QName(NAMESPACE_URI, "MyTopic", PREFIX);
> > >
> > > NotificationConsumer wsn =
> > >
> (NotificationConsumer)getResource().getCapability(WsnConstants.CONSUMER_
> > > URI);
> > > wsn.addMessageListener(this);
> > > }
> > >
> > > public boolean accepts(NotificationMessage message)
> > > {
> > > // should accept only messages whose topic is MyTopic
> > > QName tn = message.getTopic();
> > > return topicname.equals(tn);
> > > }
> > >
> > > public void process(NotificationMessage message)
> > > {
> > > getLog().info("Received message:\n\n" + message);
> > > }
> > >
> > > If I print the message.getTopic() I get:
> > > {http://ws.example.com/muse/test/notification}MyParameter and not
> > > MyTopic
> > > (and consequently the process() method does not get called)...In
> > > addition,
> > > if I look the soap messages stores in the logfile of the consumer, I
> do
> > > not
> > > see anywhere neither "MyParameterUpdate" (the name of the message I
> set
> > > up
> > > in setMyParameter) nor "MyParameter has been updated." Could anyone
> > > explain
> > > to me this behaviour?
> > > What's the difference between the use of accept() method into the
> > > consumer
> > > application and the use of producer.subscribe(consumer, new
> > > TopicFilter(qname),null) in the external class that subscribes the
> > > consumer
> > > to the producer?
> > >
> > > Thanks and sorry for the long post,
> > > Marco
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > For additional commands, e-mail: [EMAIL PROTECTED]
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > For additional commands, e-mail: [EMAIL PROTECTED]
> > >
> > >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]