You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@qpid.apache.org by Rajith Attapattu <ra...@gmail.com> on 2006/12/08 22:05:02 UTC

Unsubscribing from a topic

Hi Folks,

I ran into the following issue when fixing jms compliance tests.

As part of the spec we need to throw
javax.jms.InvalidDestinationExceptionis the name supplied in the
unsubscribe method is not valid.
So in order to detect that

a) The broker should send an error message saying that it didn't find a
queue by that name (slow) OR
b) We maintain a list of topic names on the client side (fast)

I prefer the first approach as we also need to throw an exception if this
topic (queue in topic exchange) has active consumers bound to it.
Here is the method in question. (I have also cut/paste the section from the
java doc)

public void unsubscribe(String name) throws JMSException
    {
        checkNotClosed();

        //send a queue.delete for the subscription
        String queue = _connection.getClientID() + ":" + name;
        AMQFrame frame = QueueDeleteBody.createAMQFrame(_channelId, 0,
queue, false, false, true);
        _connection.getProtocolHandler().writeFrame(frame);
    }
-----------------------------------------------------------------------------------------------------------------------------------------------------

unsubscribe

public void *unsubscribe*(java.lang.String name)
                 throws JMSException
<file:///home/rajith/Desktop/jms1.1/doc/api/javax/jms/JMSException.html>

Unsubscribes a durable subscription that has been created by a client.

This method deletes the state being maintained on behalf of the subscriber
by its provider.

It is erroneous for a client to delete a durable subscription while there is
an active MessageConsumer or TopicSubscriber for the subscription, or while
a consumed message is part of a pending transaction or has not been
acknowledged in the session.
*Parameters:*name - the name used to identify this subscription*Throws:*
JMSException<file:///home/rajith/Desktop/jms1.1/doc/api/javax/jms/JMSException.html>-
if the session fails to unsubscribe to the durable subscription due to
some internal error.InvalidDestinationException<file:///home/rajith/Desktop/jms1.1/doc/api/javax/jms/InvalidDestinationException.html>-
if an invalid subscription name is specified.
*Since: *1.1 Regards,
Rajith

Re: Unsubscribing from a topic

Posted by Gordon Sim <gs...@redhat.com>.
Rajith Attapattu wrote:
> As part of the spec we need to throw
> javax.jms.InvalidDestinationExceptionis the name supplied in the
> unsubscribe method is not valid.
> So in order to detect that

[...]

> I prefer the first approach as we also need to throw an exception if this
> topic (queue in topic exchange) has active consumers bound to it.
> Here is the method in question. (I have also cut/paste the section from the
> java doc)
> 
> public void unsubscribe(String name) throws JMSException
>    {
>        checkNotClosed();
> 
>        //send a queue.delete for the subscription
>        String queue = _connection.getClientID() + ":" + name;
>        AMQFrame frame = QueueDeleteBody.createAMQFrame(_channelId, 0,
> queue, false, false, true);
>        _connection.getProtocolHandler().writeFrame(frame);
>    }

You can use the 'ifUnused' flag (the first boolean field, occurring 
after queue) to prevent deletion if there are consumers active. However, 
as with all errors in AMQP, this results in the channel being closed. 
The same would happen if the queue name does not exist.

To avoid the pain of having to recreate all the state of the current 
channel, it might be better to have a separate channel for this purpose.

The java broker will send the correct channel exception for an unknown 
queue but does not yet do so for the ifUnused (or ifEmpty) flags (queues 
are also removed from store regardless of these flags). The c++ broker 
does currently support these flags and there are tests in the python 
test suite for this.