001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.activemq.camel; 018 019 import javax.jms.JMSException; 020 import javax.jms.Message; 021 import javax.jms.Topic; 022 import javax.jms.TopicPublisher; 023 024 import org.apache.activemq.ActiveMQSession; 025 import org.apache.camel.Endpoint; 026 027 /** 028 * A JMS {@link javax.jms.TopicPublisher} which sends message exchanges to a 029 * Camel {@link Endpoint} 030 * 031 * @version $Revision: $ 032 */ 033 public class CamelTopicPublisher extends CamelMessageProducer implements TopicPublisher { 034 035 public CamelTopicPublisher(CamelTopic destination, Endpoint endpoint, ActiveMQSession session) throws JMSException { 036 super(destination, endpoint, session); 037 } 038 039 040 /** 041 * Gets the topic associated with this <CODE>TopicPublisher</CODE>. 042 * 043 * @return this publisher's topic 044 * @throws JMSException if the JMS provider fails to get the topic for this 045 * <CODE>TopicPublisher</CODE> due to some internal error. 046 */ 047 048 public Topic getTopic() throws JMSException { 049 return (Topic) super.getDestination(); 050 } 051 052 /** 053 * Publishes a message to the topic. Uses the <CODE>TopicPublisher</CODE>'s 054 * default delivery mode, priority, and time to live. 055 * 056 * @param message the message to publish 057 * @throws JMSException if the JMS provider fails to publish the message due to 058 * some internal error. 059 * @throws javax.jms.MessageFormatException if an invalid message is specified. 060 * @throws javax.jms.InvalidDestinationException if a client uses this method with a <CODE>TopicPublisher 061 * </CODE> with an invalid topic. 062 * @throws java.lang.UnsupportedOperationException 063 * if a client uses this method with a <CODE>TopicPublisher 064 * </CODE> that did not specify a topic at creation time. 065 * @see javax.jms.MessageProducer#getDeliveryMode() 066 * @see javax.jms.MessageProducer#getTimeToLive() 067 * @see javax.jms.MessageProducer#getPriority() 068 */ 069 070 public void publish(Message message) throws JMSException { 071 super.send(message); 072 } 073 074 /** 075 * Publishes a message to the topic, specifying delivery mode, priority, 076 * and time to live. 077 * 078 * @param message the message to publish 079 * @param deliveryMode the delivery mode to use 080 * @param priority the priority for this message 081 * @param timeToLive the message's lifetime (in milliseconds) 082 * @throws JMSException if the JMS provider fails to publish the message due to 083 * some internal error. 084 * @throws javax.jms.MessageFormatException if an invalid message is specified. 085 * @throws javax.jms.InvalidDestinationException if a client uses this method with a <CODE>TopicPublisher 086 * </CODE> with an invalid topic. 087 * @throws java.lang.UnsupportedOperationException 088 * if a client uses this method with a <CODE>TopicPublisher 089 * </CODE> that did not specify a topic at creation time. 090 */ 091 092 public void publish(Message message, int deliveryMode, int priority, 093 long timeToLive) throws JMSException { 094 super.send(message, deliveryMode, priority, timeToLive); 095 } 096 097 /** 098 * Publishes a message to a topic for an unidentified message producer. 099 * Uses the <CODE>TopicPublisher</CODE>'s default delivery mode, 100 * priority, and time to live. 101 * <p/> 102 * <P> 103 * Typically, a message producer is assigned a topic at creation time; 104 * however, the JMS API also supports unidentified message producers, which 105 * require that the topic be supplied every time a message is published. 106 * 107 * @param topic the topic to publish this message to 108 * @param message the message to publish 109 * @throws JMSException if the JMS provider fails to publish the message due to 110 * some internal error. 111 * @throws javax.jms.MessageFormatException if an invalid message is specified. 112 * @throws javax.jms.InvalidDestinationException if a client uses this method with an invalid topic. 113 * @see javax.jms.MessageProducer#getDeliveryMode() 114 * @see javax.jms.MessageProducer#getTimeToLive() 115 * @see javax.jms.MessageProducer#getPriority() 116 */ 117 118 public void publish(Topic topic, Message message) throws JMSException { 119 super.send(topic, message); 120 } 121 122 /** 123 * Publishes a message to a topic for an unidentified message producer, 124 * specifying delivery mode, priority and time to live. 125 * <p/> 126 * <P> 127 * Typically, a message producer is assigned a topic at creation time; 128 * however, the JMS API also supports unidentified message producers, which 129 * require that the topic be supplied every time a message is published. 130 * 131 * @param topic the topic to publish this message to 132 * @param message the message to publish 133 * @param deliveryMode the delivery mode to use 134 * @param priority the priority for this message 135 * @param timeToLive the message's lifetime (in milliseconds) 136 * @throws JMSException if the JMS provider fails to publish the message due to 137 * some internal error. 138 * @throws javax.jms.MessageFormatException if an invalid message is specified. 139 * @throws javax.jms.InvalidDestinationException if a client uses this method with an invalid topic. 140 */ 141 142 public void publish(Topic topic, Message message, int deliveryMode, 143 int priority, long timeToLive) throws JMSException { 144 super.send(topic, message, deliveryMode, priority, timeToLive); 145 } 146 }