public class DefaultMQPushConsumer extends ClientConfig implements MQPushConsumer
Thread Safety: After initialization, the instance can be regarded as thread-safe.
Modifier and Type | Field and Description |
---|---|
protected DefaultMQPushConsumerImpl |
defaultMQPushConsumerImpl
Internal implementation.
|
SEND_MESSAGE_WITH_VIP_CHANNEL_PROPERTY
Constructor and Description |
---|
DefaultMQPushConsumer()
Default constructor.
|
DefaultMQPushConsumer(RPCHook rpcHook)
Constructor specifying RPC hook.
|
DefaultMQPushConsumer(java.lang.String consumerGroup,
RPCHook rpcHook,
AllocateMessageQueueStrategy allocateMessageQueueStrategy)
Constructor specifying consumer group, RPC hook and message queue allocating algorithm.
|
Modifier and Type | Method and Description |
---|---|
void |
createTopic(java.lang.String key,
java.lang.String newTopic,
int queueNum)
Creates an topic
|
void |
createTopic(java.lang.String key,
java.lang.String newTopic,
int queueNum,
int topicSysFlag)
Creates an topic
|
long |
earliestMsgStoreTime(MessageQueue mq)
Gets the earliest stored message time
|
java.util.Set<MessageQueue> |
fetchSubscribeMessageQueues(java.lang.String topic)
Fetch message queues from consumer cache according to the topic
|
long |
getAdjustThreadPoolNumsThreshold() |
AllocateMessageQueueStrategy |
getAllocateMessageQueueStrategy() |
int |
getConsumeConcurrentlyMaxSpan() |
ConsumeFromWhere |
getConsumeFromWhere() |
int |
getConsumeMessageBatchMaxSize() |
java.lang.String |
getConsumerGroup() |
int |
getConsumeThreadMax() |
int |
getConsumeThreadMin() |
long |
getConsumeTimeout() |
java.lang.String |
getConsumeTimestamp() |
DefaultMQPushConsumerImpl |
getDefaultMQPushConsumerImpl() |
int |
getMaxReconsumeTimes() |
MessageListener |
getMessageListener() |
MessageModel |
getMessageModel() |
OffsetStore |
getOffsetStore() |
int |
getPullBatchSize() |
long |
getPullInterval() |
int |
getPullThresholdForQueue() |
java.util.Map<java.lang.String,java.lang.String> |
getSubscription() |
long |
getSuspendCurrentQueueTimeMillis() |
boolean |
isPostSubscriptionWhenPull() |
boolean |
isUnitMode() |
long |
maxOffset(MessageQueue mq)
Gets the max offset
|
long |
minOffset(MessageQueue mq)
Gets the minimum offset
|
QueryResult |
queryMessage(java.lang.String topic,
java.lang.String key,
int maxNum,
long begin,
long end)
Query messages
|
void |
registerMessageListener(MessageListener messageListener)
Deprecated.
|
void |
registerMessageListener(MessageListenerConcurrently messageListener)
Register a callback to execute on message arrival for concurrent consuming.
|
void |
registerMessageListener(MessageListenerOrderly messageListener)
Register a callback to execute on message arrival for orderly consuming.
|
void |
resume()
Resume pulling.
|
long |
searchOffset(MessageQueue mq,
long timestamp)
Gets the message queue offset according to some time in milliseconds
be cautious to call because of more IO overhead |
void |
sendMessageBack(MessageExt msg,
int delayLevel)
Send message back to broker which will be re-delivered in future.
|
void |
sendMessageBack(MessageExt msg,
int delayLevel,
java.lang.String brokerName)
Send message back to the broker whose name is
brokerName and the message will be re-delivered in
future. |
void |
setAdjustThreadPoolNumsThreshold(long adjustThreadPoolNumsThreshold) |
void |
setAllocateMessageQueueStrategy(AllocateMessageQueueStrategy allocateMessageQueueStrategy) |
void |
setConsumeConcurrentlyMaxSpan(int consumeConcurrentlyMaxSpan) |
void |
setConsumeFromWhere(ConsumeFromWhere consumeFromWhere) |
void |
setConsumeMessageBatchMaxSize(int consumeMessageBatchMaxSize) |
void |
setConsumerGroup(java.lang.String consumerGroup) |
void |
setConsumeThreadMax(int consumeThreadMax) |
void |
setConsumeThreadMin(int consumeThreadMin) |
void |
setConsumeTimeout(long consumeTimeout) |
void |
setConsumeTimestamp(java.lang.String consumeTimestamp) |
void |
setMaxReconsumeTimes(int maxReconsumeTimes) |
void |
setMessageListener(MessageListener messageListener) |
void |
setMessageModel(MessageModel messageModel) |
void |
setOffsetStore(OffsetStore offsetStore) |
void |
setPostSubscriptionWhenPull(boolean postSubscriptionWhenPull) |
void |
setPullBatchSize(int pullBatchSize) |
void |
setPullInterval(long pullInterval) |
void |
setPullThresholdForQueue(int pullThresholdForQueue) |
void |
setSubscription(java.util.Map<java.lang.String,java.lang.String> subscription) |
void |
setSuspendCurrentQueueTimeMillis(long suspendCurrentQueueTimeMillis) |
void |
setUnitMode(boolean isUnitMode) |
void |
shutdown()
Shut down this client and releasing underlying resources.
|
void |
start()
This method gets internal infrastructure readily to serve.
|
void |
subscribe(java.lang.String topic,
MessageSelector messageSelector)
Subscribe a topic by message selector.
|
void |
subscribe(java.lang.String topic,
java.lang.String subExpression)
Subscribe a topic to consuming subscription.
|
void |
subscribe(java.lang.String topic,
java.lang.String fullClassName,
java.lang.String filterClassSource)
Subscribe a topic to consuming subscription.
|
void |
suspend()
Suspend pulling new messages.
|
void |
unsubscribe(java.lang.String topic)
Un-subscribe the specified topic from subscription.
|
void |
updateCorePoolSize(int corePoolSize)
Update the message consuming thread core pool size.
|
MessageExt |
viewMessage(java.lang.String offsetMsgId)
Query message according tto message id
|
MessageExt |
viewMessage(java.lang.String topic,
java.lang.String msgId) |
buildMQClientId, changeInstanceNameToPID, cloneClientConfig, getClientCallbackExecutorThreads, getClientIP, getHeartbeatBrokerInterval, getInstanceName, getNamesrvAddr, getPersistConsumerOffsetInterval, getPollNameServerInterval, getUnitName, isVipChannelEnabled, resetClientConfig, setClientCallbackExecutorThreads, setClientIP, setHeartbeatBrokerInterval, setInstanceName, setNamesrvAddr, setPersistConsumerOffsetInterval, setPollNameServerInterval, setUnitName, setVipChannelEnabled, toString
protected final transient DefaultMQPushConsumerImpl defaultMQPushConsumerImpl
public DefaultMQPushConsumer()
public DefaultMQPushConsumer(java.lang.String consumerGroup, RPCHook rpcHook, AllocateMessageQueueStrategy allocateMessageQueueStrategy)
consumerGroup
- Consume queue.rpcHook
- RPC hook to execute before each remoting command.allocateMessageQueueStrategy
- message queue allocating algorithm.public DefaultMQPushConsumer(RPCHook rpcHook)
rpcHook
- RPC hook to execute before each remoting command.public void createTopic(java.lang.String key, java.lang.String newTopic, int queueNum) throws MQClientException
MQAdmin
createTopic
in interface MQAdmin
key
- accesskeynewTopic
- topic namequeueNum
- topic's queue numberMQClientException
public void createTopic(java.lang.String key, java.lang.String newTopic, int queueNum, int topicSysFlag) throws MQClientException
MQAdmin
createTopic
in interface MQAdmin
key
- accesskeynewTopic
- topic namequeueNum
- topic's queue numbertopicSysFlag
- topic system flagMQClientException
public long searchOffset(MessageQueue mq, long timestamp) throws MQClientException
MQAdmin
searchOffset
in interface MQAdmin
mq
- Instance of MessageQueuetimestamp
- from when in milliseconds.MQClientException
public long maxOffset(MessageQueue mq) throws MQClientException
MQAdmin
maxOffset
in interface MQAdmin
mq
- Instance of MessageQueueMQClientException
public long minOffset(MessageQueue mq) throws MQClientException
MQAdmin
minOffset
in interface MQAdmin
mq
- Instance of MessageQueueMQClientException
public long earliestMsgStoreTime(MessageQueue mq) throws MQClientException
MQAdmin
earliestMsgStoreTime
in interface MQAdmin
mq
- Instance of MessageQueueMQClientException
public MessageExt viewMessage(java.lang.String offsetMsgId) throws RemotingException, MQBrokerException, java.lang.InterruptedException, MQClientException
MQAdmin
viewMessage
in interface MQAdmin
offsetMsgId
- message idRemotingException
MQBrokerException
java.lang.InterruptedException
MQClientException
public QueryResult queryMessage(java.lang.String topic, java.lang.String key, int maxNum, long begin, long end) throws MQClientException, java.lang.InterruptedException
MQAdmin
queryMessage
in interface MQAdmin
topic
- message topickey
- message key index wordmaxNum
- max message numberbegin
- from whenend
- to whenMQClientException
java.lang.InterruptedException
public MessageExt viewMessage(java.lang.String topic, java.lang.String msgId) throws RemotingException, MQBrokerException, java.lang.InterruptedException, MQClientException
viewMessage
in interface MQAdmin
MessageExt
of given msgIdRemotingException
MQBrokerException
java.lang.InterruptedException
MQClientException
public AllocateMessageQueueStrategy getAllocateMessageQueueStrategy()
public void setAllocateMessageQueueStrategy(AllocateMessageQueueStrategy allocateMessageQueueStrategy)
public int getConsumeConcurrentlyMaxSpan()
public void setConsumeConcurrentlyMaxSpan(int consumeConcurrentlyMaxSpan)
public ConsumeFromWhere getConsumeFromWhere()
public void setConsumeFromWhere(ConsumeFromWhere consumeFromWhere)
public int getConsumeMessageBatchMaxSize()
public void setConsumeMessageBatchMaxSize(int consumeMessageBatchMaxSize)
public java.lang.String getConsumerGroup()
public void setConsumerGroup(java.lang.String consumerGroup)
public int getConsumeThreadMax()
public void setConsumeThreadMax(int consumeThreadMax)
public int getConsumeThreadMin()
public void setConsumeThreadMin(int consumeThreadMin)
public DefaultMQPushConsumerImpl getDefaultMQPushConsumerImpl()
public MessageListener getMessageListener()
public void setMessageListener(MessageListener messageListener)
public MessageModel getMessageModel()
public void setMessageModel(MessageModel messageModel)
public int getPullBatchSize()
public void setPullBatchSize(int pullBatchSize)
public long getPullInterval()
public void setPullInterval(long pullInterval)
public int getPullThresholdForQueue()
public void setPullThresholdForQueue(int pullThresholdForQueue)
public java.util.Map<java.lang.String,java.lang.String> getSubscription()
public void setSubscription(java.util.Map<java.lang.String,java.lang.String> subscription)
public void sendMessageBack(MessageExt msg, int delayLevel) throws RemotingException, MQBrokerException, java.lang.InterruptedException, MQClientException
sendMessageBack
in interface MQConsumer
msg
- Message to send back.delayLevel
- delay level.RemotingException
- if there is any network-tier error.MQBrokerException
- if there is any broker error.java.lang.InterruptedException
- if the thread is interrupted.MQClientException
- if there is any client error.public void sendMessageBack(MessageExt msg, int delayLevel, java.lang.String brokerName) throws RemotingException, MQBrokerException, java.lang.InterruptedException, MQClientException
brokerName
and the message will be re-delivered in
future.sendMessageBack
in interface MQConsumer
msg
- Message to send back.delayLevel
- delay level.brokerName
- broker name.RemotingException
- if there is any network-tier error.MQBrokerException
- if there is any broker error.java.lang.InterruptedException
- if the thread is interrupted.MQClientException
- if there is any client error.public java.util.Set<MessageQueue> fetchSubscribeMessageQueues(java.lang.String topic) throws MQClientException
MQConsumer
fetchSubscribeMessageQueues
in interface MQConsumer
topic
- message topicMQClientException
public void start() throws MQClientException
start
in interface MQPushConsumer
MQClientException
- if there is any client error.public void shutdown()
shutdown
in interface MQPushConsumer
@Deprecated public void registerMessageListener(MessageListener messageListener)
MQPushConsumer
registerMessageListener
in interface MQPushConsumer
public void registerMessageListener(MessageListenerConcurrently messageListener)
registerMessageListener
in interface MQPushConsumer
messageListener
- message handling callback.public void registerMessageListener(MessageListenerOrderly messageListener)
registerMessageListener
in interface MQPushConsumer
messageListener
- message handling callback.public void subscribe(java.lang.String topic, java.lang.String subExpression) throws MQClientException
subscribe
in interface MQPushConsumer
topic
- topic to subscribe.subExpression
- subscription expression.it only support or operation such as "tag1 || tag2 || tag3" MQClientException
- if there is any client error.public void subscribe(java.lang.String topic, java.lang.String fullClassName, java.lang.String filterClassSource) throws MQClientException
subscribe
in interface MQPushConsumer
topic
- topic to consume.fullClassName
- full class name,must extend org.apache.rocketmq.common.filter. MessageFilterfilterClassSource
- class source code,used UTF-8 file encoding,must be responsible for your code safetyMQClientException
public void subscribe(java.lang.String topic, MessageSelector messageSelector) throws MQClientException
subscribe
in interface MQPushConsumer
topic
- topic to consume.messageSelector
- MessageSelector
MQClientException
MessageSelector.bySql(java.lang.String)
,
MessageSelector.byTag(java.lang.String)
public void unsubscribe(java.lang.String topic)
unsubscribe
in interface MQPushConsumer
topic
- message topicpublic void updateCorePoolSize(int corePoolSize)
updateCorePoolSize
in interface MQPushConsumer
corePoolSize
- new core pool size.public void suspend()
suspend
in interface MQPushConsumer
public void resume()
resume
in interface MQPushConsumer
public OffsetStore getOffsetStore()
public void setOffsetStore(OffsetStore offsetStore)
public java.lang.String getConsumeTimestamp()
public void setConsumeTimestamp(java.lang.String consumeTimestamp)
public boolean isPostSubscriptionWhenPull()
public void setPostSubscriptionWhenPull(boolean postSubscriptionWhenPull)
public boolean isUnitMode()
isUnitMode
in class ClientConfig
public void setUnitMode(boolean isUnitMode)
setUnitMode
in class ClientConfig
public long getAdjustThreadPoolNumsThreshold()
public void setAdjustThreadPoolNumsThreshold(long adjustThreadPoolNumsThreshold)
public int getMaxReconsumeTimes()
public void setMaxReconsumeTimes(int maxReconsumeTimes)
public long getSuspendCurrentQueueTimeMillis()
public void setSuspendCurrentQueueTimeMillis(long suspendCurrentQueueTimeMillis)
public long getConsumeTimeout()
public void setConsumeTimeout(long consumeTimeout)