metaq 消费者机制

重点代码如下:

public class AsyncConsumer {
    public static void main(final String[] args) throws Exception {
        // New session factory,强烈建议使用单例
        final MessageSessionFactory sessionFactory = new MetaMessageSessionFactory(initMetaConfig());

        // subscribed topic
        final String topic = "meta-test";
        // consumer group
        final String group = "meta-example";
        // create consumer,强烈建议使用单例
        ConsumerConfig consumerConfig = new ConsumerConfig(group);
        // 默认最大获取延迟为5秒,这里设置成100毫秒,请根据实际应用要求做设置。
        consumerConfig.setMaxDelayFetchTimeInMills(100);
        final MessageConsumer consumer = sessionFactory.createConsumer(consumerConfig);
        // subscribe topic
        consumer.subscribe(topic, 1024 * 1024, new MessageListener() {

            @Override
            public void recieveMessages(final Message message) {
                System.out.println("Receive message " + new String(message.getData()));
            }


            @Override
            public Executor getExecutor() {
                // Thread pool to process messages,maybe null.
                return null;
            }
        });
        // complete subscribe
        consumer.completeSubscribe();

    }

}


执行完成后 在zookeeper  里面显示的图片

185902_IHyw_110387.png

 [system]
brokerId=40
numPartitions=2
serverPort=61616
dashboardHttpPort=8120
unflushThreshold=1000
unflushInterval=10000
maxSegmentSize=1073741824
maxTransferSize=20971520
deletePolicy=delete,24
deleteWhen=0 0 6,18 * * ?
flushTxLogAtCommit=1
stat=true
dataPath=/data/
getProcessThreadCount=100
putProcessThreadCount=100

;; Update consumers offsets to current max offsets when consumers offsets are out of range of current broker's messages.
;; It must be false in production.But recommend to be true in development or test.
updateConsumerOffsets=false

[zookeeper]
zk.zkConnect=10.201.2.31:5181,10.201.2.32:5181,10.201.2.33:5181
zk.zkSessionTimeoutMs=30000
zk.zkConnectionTimeoutMs=30000
zk.zkSyncTimeMs=5000

;; Topics section
[topic=distributed_cache]
[topic=message_transfer_topic]
numPartitions=20


220221_iDeu_110387.png



224427_pNIi_110387.png

转载于:https://my.oschina.net/makemyownlife/blog/521589

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值