You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@qpid.apache.org by si...@gmail.com on 2012/02/10 10:21:28 UTC
Adding and deleting queues and exchanges programatically
Hi,
Can someone explain how to add and delete queues and exchanges
programatically? In qpid-0.14,queueDeclare() and exchangeDeclare() seems
to be obsolete. Please correct me if iam wrong.
Moreover we normally use qpid-config to add and delete queues and
exchanges. But how to do the same in c++ code.Can someone explain with some
small example.
Regards,
Sinduja.R
Re: Adding and deleting queues and exchanges programatically
Posted by Fraser Adams <fr...@blueyonder.co.uk>.
Hi Sindura,
The way to do it programatically is to use QMF (the Qpid Management
Framework). It's not too complicated, but unfortunately it's not trivial
either. Apologies for the long response, but I hope it's enough to get
you started.
There's definitely enough information here, so the exam question is for
you to to put it into practice. If you put together a sample please do
post it back to the group.
The protocol is basically a series of Map Messages.
The protocol is documented here:
https://cwiki.apache.org/qpid/qmf-map-message-protocol.html
and the API documented here
https://cwiki.apache.org/qpid/qmfv2-api-proposal.html
It's a shame that you're using C++ as I've actually recently written a
Java implementation of the QMF2 API for Java, see
https://issues.apache.org/jira/browse/QPID-3675?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
There is a C++ API of sorts, however to date it doesn't appear to
conform in any way to the QMF2 API that I linked above :-( if I get time
I might look into writing one, but I need to get a life after doing the
Java one. Plus nobody seems to be biting on the Java one so I've no idea
whether it's actually worth doing.
For what it's worth the place to look to figure out how to use the
current C++ API is (IIRC) in here "qpid/cpp/src/qmf". I think you'd use
the ConsoleSession to retrieve the broker ManagementObject and invoke
the create method on that. I'm afraid though that I'm not familiar with
this API and have never used it.
Gordon Sim, who's something of a Qpid guru put together a few examples
of using the QMF2 MapMessage protocol directly in C++ you might actually
get more mileage out of these than the existing C++ API. I've attached
them here though I can't take any credit for them.
test1.cpp illustrates how to get the message depth from a specified queue
test2.cpp illustrates how to delete a queue (create uses the "create"
method and you specify the arguments etc. via Variant::Map properties)
example.cpp illustrates how to create links and bridges (essentially how
qpid-route works)
I've also attached some help that Gordon put together.
With respect to creating queues/exchanges via QMF2. My Java QMF2
implementation actually includes a Java port of qpid-config that happens
to implement QpidConfig add queue/exchange del queue/exchange via QMF2.
Although I use the API you still have to pass the parameters to the
create method as Map Messages. I've copied the Java code for creating
queues and exchanges below so you should be able to use this in
conjunction with Gordon's test2.cpp to get you going (assuming that
you've got some reasonable C++ behind you). BTW QmfData below is just a
wrapper for a Map that provides a number of accessor/mutator methods,
the bit that you care about is the properties Map. In C++ I think you'd
create a Variant::Map and populate that in a similar way to what I've
done below and pass that Variant::Map as a property called "properties"
in code based on test2.cpp attached
HTH
Frase
/**
* Add an exchange using the QMF "create" method.
* @param args the exchange type is the first argument and the
exchange name is the second argument.
* The remaining QMF method properties are populated form config
parsed from the command line.
*/
private void addExchange(final String[] args)
{
if (args.length < 2)
{
usage();
}
Map<String, Object> properties = new HashMap<String, Object>();
if (_durable)
{
properties.put("durable", true);
}
properties.put("exchange-type", args[0]);
if (_msgSequence)
{
properties.put(MSG_SEQUENCE, 1l);
}
if (_ive)
{
properties.put(IVE, 1l);
}
if (_altExchange != null)
{
properties.put("alternate-exchange", _altExchange);
}
QmfData arguments = new QmfData();
arguments.setValue("type", "exchange");
arguments.setValue("name", args[1]);
arguments.setValue("properties", properties);
try
{
_broker.invokeMethod("create", arguments);
}
catch (QmfException e)
{
System.out.println(e.getMessage());
}
// passive exchange creation not implemented yet (not sure how
to do it using QMF2)
}
/**
* Add a queue using the QMF "create" method.
* @param args the queue name is the first argument.
* The remaining QMF method properties are populated form config
parsed from the command line.
*/
private void addQueue(final String[] args)
{
if (args.length < 1)
{
usage();
}
Map<String, Object> properties = new HashMap<String, Object>();
for (String a : extraArguments)
{
String[] r = a.split("=");
String value = r.length == 2 ? r[1] : null;
properties.put(r[0], value);
}
if (_durable)
{
properties.put("durable", true);
properties.put(FILECOUNT, _fileCount);
properties.put(FILESIZE, _fileSize);
}
if (_maxQueueSize > 0)
{
properties.put(MAX_QUEUE_SIZE, _maxQueueSize);
}
if (_maxQueueCount > 0)
{
properties.put(MAX_QUEUE_COUNT, _maxQueueCount);
}
if (_limitPolicy.equals("reject"))
{
properties.put(POLICY_TYPE, "reject");
}
else if (_limitPolicy.equals("flow-to-disk"))
{
properties.put(POLICY_TYPE, "flow_to_disk");
}
else if (_limitPolicy.equals("ring"))
{
properties.put(POLICY_TYPE, "ring");
}
else if (_limitPolicy.equals("ring-strict"))
{
properties.put(POLICY_TYPE, "ring_strict");
}
if (_clusterDurable)
{
properties.put(CLUSTER_DURABLE, 1l);
}
if (_order.equals("lvq"))
{
properties.put(LVQ, 1l);
}
else if (_order.equals("lvq-no-browse"))
{
properties.put(LVQNB, 1l);
}
if (_eventGeneration > 0)
{
properties.put(QUEUE_EVENT_GENERATION, _eventGeneration);
}
if (_altExchange != null)
{
properties.put("alternate-exchange", _altExchange);
}
if (_flowStopSize > 0)
{
properties.put(FLOW_STOP_SIZE, _flowStopSize);
}
if (_flowResumeSize > 0)
{
properties.put(FLOW_RESUME_SIZE, _flowResumeSize);
}
if (_flowStopCount > 0)
{
properties.put(FLOW_STOP_COUNT, _flowStopCount);
}
if (_flowResumeCount > 0)
{
properties.put(FLOW_RESUME_COUNT, _flowResumeCount);
}
QmfData arguments = new QmfData();
arguments.setValue("type", "queue");
arguments.setValue("name", args[0]);
arguments.setValue("properties", properties);
try
{
_broker.invokeMethod("create", arguments);
}
catch (QmfException e)
{
System.out.println(e.getMessage());
}
// passive queue creation not implemented yet (not sure how to
do it using QMF2)
}
/**
* Remove an exchange using the QMF "delete" method.
* @param args the exchange name is the first argument.
* The remaining QMF method properties are populated form config
parsed from the command line.
*/
private void delExchange(final String[] args)
{
if (args.length < 1)
{
usage();
}
QmfData arguments = new QmfData();
arguments.setValue("type", "exchange");
arguments.setValue("name", args[0]);
try
{
_broker.invokeMethod("delete", arguments);
}
catch (QmfException e)
{
System.out.println(e.getMessage());
}
}
On 10/02/12 09:21, sinduja.ramaraj@gmail.com wrote:
> Hi,
>
> Can someone explain how to add and delete queues and exchanges
> programatically? In qpid-0.14,queueDeclare() and exchangeDeclare() seems
> to be obsolete. Please correct me if iam wrong.
> Moreover we normally use qpid-config to add and delete queues and
> exchanges. But how to do the same in c++ code.Can someone explain with some
> small example.
>
> Regards,
> Sinduja.R
>