alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

ActiveMQ example source code file (ActiveMQTopicSubscriber.java)

This example ActiveMQ source code file (ActiveMQTopicSubscriber.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - ActiveMQ tags/keywords

activemqdestination, activemqmessageconsumer, activemqtopicsubscriber, activemqtopicsubscriber, consumerid, jmsexception, jmsexception, string, string, topic, topic, topicsubscriber

The ActiveMQ ActiveMQTopicSubscriber.java source code

/**
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.activemq;

import javax.jms.JMSException;
import javax.jms.Topic;
import javax.jms.TopicSubscriber;

import org.apache.activemq.command.ActiveMQDestination;
import org.apache.activemq.command.ConsumerId;

/**
 * A client uses a <CODE>TopicSubscriber object to receive messages
 * that have been published to a topic. A <CODE>TopicSubscriber object
 * is the publish/subscribe form of a message consumer. A <CODE>
 * MessageConsumer</CODE> can be created by using 
 * Session.createConsumer</CODE>.
 * <p/>
 * <P>
 * A <CODE>TopicSession allows the creation of multiple 
 * TopicSubscriber</CODE> objects per topic. It will deliver each message for
 * a topic to each subscriber eligible to receive it. Each copy of the message
 * is treated as a completely separate message. Work done on one copy has no
 * effect on the others; acknowledging one does not acknowledge the others; one
 * message may be delivered immediately, while another waits for its subscriber
 * to process messages ahead of it.
 * <p/>
 * <P>
 * Regular <CODE>TopicSubscriber objects are not durable. They receive
 * only messages that are published while they are active.
 * <p/>
 * <P>
 * Messages filtered out by a subscriber's message selector will never be
 * delivered to the subscriber. From the subscriber's perspective, they do not
 * exist.
 * <p/>
 * <P>
 * In some cases, a connection may both publish and subscribe to a topic. The
 * subscriber <CODE>NoLocal attribute allows a subscriber to inhibit
 * the delivery of messages published by its own connection.
 * <p/>
 * <P>
 * If a client needs to receive all the messages published on a topic,
 * including the ones published while the subscriber is inactive, it uses a
 * durable <CODE>TopicSubscriber. The JMS provider retains a record
 * of this durable subscription and insures that all messages from the topic's
 * publishers are retained until they are acknowledged by this durable
 * subscriber or they have expired.
 * <p/>
 * <P>
 * Sessions with durable subscribers must always provide the same client
 * identifier. In addition, each client must specify a name that uniquely
 * identifies (within client identifier) each durable subscription it creates.
 * Only one session at a time can have a <CODE>TopicSubscriber for a
 * particular durable subscription.
 * <p/>
 * <P>
 * A client can change an existing durable subscription by creating a durable
 * <CODE>TopicSubscriber with the same name and a new topic and/or
 * message selector. Changing a durable subscription is equivalent to
 * unsubscribing (deleting) the old one and creating a new one.
 * <p/>
 * <P>
 * The <CODE>unsubscribe method is used to delete a durable
 * subscription. The <CODE>unsubscribe method can be used at the
 * <CODE>Session or TopicSession level. This method
 * deletes the state being maintained on behalf of the subscriber by its
 * provider.
 * <p/>
 * <P>
 * Creating a <CODE>MessageConsumer provides the same features as
 * creating a <CODE>TopicSubscriber. To create a durable subscriber,
 * use of <CODE>Session.CreateDurableSubscriber is recommended. The
 * <CODE>TopicSubscriber is provided to support existing code.
 *
 * @see javax.jms.Session#createConsumer
 * @see javax.jms.Session#createDurableSubscriber
 * @see javax.jms.TopicSession
 * @see javax.jms.TopicSession#createSubscriber
 * @see javax.jms.TopicSubscriber
 * @see javax.jms.MessageConsumer
 */

public class ActiveMQTopicSubscriber extends ActiveMQMessageConsumer implements
        TopicSubscriber {

    /**
     * @param theSession
     * @param value 
     * @param dest
     * @param name
     * @param selector
     * @param cnum
     * @param noLocalValue
     * @param browserValue
     * @param asyncDispatch 
     * @throws JMSException
     */
    protected ActiveMQTopicSubscriber(ActiveMQSession theSession,
                                      ConsumerId consumerId, ActiveMQDestination dest, String name, String selector, int prefetch, int maximumPendingMessageCount,
                                      boolean noLocalValue, boolean browserValue, boolean asyncDispatch) throws JMSException {
        super(theSession, consumerId, dest, name, selector, prefetch, maximumPendingMessageCount, noLocalValue, browserValue, asyncDispatch, null);
    }

    /**
     * Gets the <CODE>Topic associated with this subscriber.
     *
     * @return this subscriber's <CODE>Topic
     * @throws JMSException if the JMS provider fails to get the topic for this topic
     *                      subscriber due to some internal error.
     */

    public Topic getTopic() throws JMSException {
        checkClosed();
        return (Topic) super.getDestination();
    }

    /**
     * Gets the <CODE>NoLocal attribute for this subscriber. The
     * default value for this attribute is false.
     *
     * @return true if locally published messages are being inhibited
     * @throws JMSException if the JMS provider fails to get the <CODE>NoLocal
     *                      </CODE> attribute for this topic subscriber due to some
     *                      internal error.
     */

    public boolean getNoLocal() throws JMSException {
        checkClosed();
        return super.isNoLocal();
    }
}

Other ActiveMQ examples (source code examples)

Here is a short list of links related to this ActiveMQ ActiveMQTopicSubscriber.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.