Hi Daryoush,

There are some basic examples in qpid/cpp/bindings/qmf2/examples/cpp/ directory.

See:

agent.cpp - an example agent that exposes some method calls (like "echo").
list_agents.cpp - an example console that listens for agents connecting to a 
broker.

Unfortunately, there are no examples of making method calls (!)

I've hacked a quick example of calling the "echo" method exported by agent.cpp. 
 If you apply the patch below to list_agents.cpp (trunk), it will attempt to 
call the "echo" method.

Fire off a broker (qpidd), start the agent.cpp executable (leave it running), 
then run the modified list_agents.cpp.

didn't test it very well, but it should give you an idea...


Index: list_agents.cpp
===================================================================
--- list_agents.cpp     (revision 1199840)
+++ list_agents.cpp     (working copy)
@@ -21,6 +21,9 @@
 #include <qpid/messaging/Duration.h>
 #include <qmf/ConsoleSession.h>
 #include <qmf/ConsoleEvent.h>
+#include <qmf/Query.h>
+#include <qmf/Data.h>
+#include <qmf/DataAddr.h>
 #include <qmf/Agent.h>
 #include <qpid/types/Variant.h>
 #include <string>
@@ -60,6 +63,40 @@
                 if (event.getAgent().getName() == 
session.getConnectedBrokerAgent().getName())
                     extra = "  [Connected Broker]";
                 cout << "Agent Added: " << event.getAgent().getName() << extra 
<< endl;
+                // find the "Profitron" agent
+                if (event.getAgent().getVendor() == "profitron.com") {
+                    Agent myAgent = event.getAgent();
+                    // query the agent for its schema
+                    ConsoleEvent schemaInfo = event.getAgent().querySchema();
+                    // cout << "Schema Count: " << 
schemaInfo.getSchemaIdCount() << endl;
+                    // Find the Schema identifier for the "control" class...
+                    for (int i = 0; i < schemaInfo.getSchemaIdCount(); ++i) {
+                        SchemaId sid = schemaInfo.getSchemaId(i);
+                        // cout << "SchemaId: " << sid.getPackageName() << ":" 
<< sid.getName() << ":" << sid.getHash() << endl;
+                        if (sid.getName() == "control") {
+                            // now query the agent for all the "control" 
objects - there is only one in this example
+                            Query q(QUERY_OBJECT_ID, sid);
+                            ConsoleEvent obj = myAgent.query(q);
+                            // cout << "Query returned=" << obj.getType() << 
endl;
+                            // "control" is a singleton, so getDataCount() 
returns 1 below
+                            for (int j = 0; j < obj.getDataCount(); ++j) {
+                                // cout << "addr= " << 
obj.getData(j).getAddr().asMap() << endl;
+
+                                // get the address of the object, so we can 
call methods against it:
+                                DataAddr myObjId = obj.getData(j).getAddr();
+                                // arguments to "echo" method
+                                Variant::Map args;
+                                Variant::Map map_data;
+                                map_data["hello"] = Variant("world!");
+                                args["sequence"] = Variant(1);
+                                args["map"] = map_data;
+                                // invoke the method synchronously
+                                ConsoleEvent rc = 
event.getAgent().callMethod("echo", args, myObjId);
+                                cout << "results=" << rc.getArguments() << 
endl;
+                            }
+                        }
+                    }
+                }
             }
             if (event.getType() == CONSOLE_AGENT_DEL) {
                 if (event.getAgentDelReason() == AGENT_DEL_AGED)






----- Original Message -----
> I need to find out of if Qpid's QMF  would work for a simple RPC
> application that I need to develop.     Any samples or tutorials
> showing
> the agent requirements would be greatly appreciated.
> 
> Thanks
> Daryoush
> 

---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:[email protected]

Reply via email to