0%

rocketmq的client在启动的时候,会通过开启一个定时任务来定期刷新topic信息,这里就来看一下这个刷新的过程。

首先来看一下这个定时任务:

1
2
3
4
5
6
7
8
9
10
11
this.scheduledExecutorService.scheduleAtFixedRate(new Runnable() {

@Override
public void run() {
try {
MQClientInstance.this.updateTopicRouteInfoFromNameServer();
} catch (Exception e) {
log.error("ScheduledTask updateTopicRouteInfoFromNameServer exception", e);
}
}
}, 10, this.clientConfig.getPollNameServerInterval(), TimeUnit.MILLISECONDS);
Read more »

producerrocketmq的作用是消息的生产者,consumerrocketmq的作用是消息的消费者,它的生命周期是跟项目相关的,即是由使用者控制的。而为什么要将这两个角色的启动关闭流程放在一起剖析呢?是因为他们都是MQ的客户端,在启动和关闭的行为上,有着很多共同的地方。接下来便将会来仔细探究其启动和关闭的过程。

Producer

DefaultMQProducer

DefaultMQProducer的启动

producer在启动的时候会做一系列的内部初始化,其启动的源码如下所示:

1
2
3
4
5
6
7
8
9
10
11
public void start() throws MQClientException {
this.setProducerGroup(withNamespace(this.producerGroup));
this.defaultMQProducerImpl.start();
if (null != traceDispatcher) {
try {
traceDispatcher.start(this.getNamesrvAddr(), this.getAccessChannel());
} catch (MQClientException e) {
log.warn("trace dispatcher start failed ", e);
}
}
}
Read more »

在rocketmq中,MQProducer是承载消息发送的,消息的发送又可以分为常规消息的发送和事务消息的发送,其中常规消息发送用的是DefaultMQProducer,事务消息的发送用的是TransactionMQProducer。他们集成关系图如:

Read more »

从功能上来说,rocketmq支持三种发送消息的方式,分别是同步发送(sync),异步发送(async)和直接发送(oneway)。下面来简单说明一下这三种发送消息的方式,以便了解它们之间的差异。

以下的案例代码将会使用spring-message风格进行展示,即使用rocketMQTemplate方式,详见rocketmq-spring

Read more »

场景

terms聚合的结果直接返给前端处理,如果bucket的key为字符串时,在mvc层jackson进行json序列化处理会报类型转换错误。

原因分析

terms聚合的结果中有keyAsNumber字段,是将桶key转为number类型,但是当key为字符串类型的数据时,是无法转为numebr类型的。

Read more »

场景

业务需求中,在计算人均通话数时,使用聚合的时候使用到了内联以及反内联聚合,当bucket_script聚合作为反内联reverse_nested的子聚和的时候,会报如下错误:

1
org.elasticsearch.ElasticsearchException: Elasticsearch exception [type=class_cast_exception, reason=org.elasticsearch.search.aggregations.bucket.nested.InternalReverseNested cannot be cast to org.elasticsearch.search.aggregations.InternalMultiBucketAggregation]
Read more »

场景

做分页查询,当分页达到一定量的时候,报如下错误:

1
Result window is too large, from + size must be less than or equal to: [10000] but was [78020]. See the scroll api for a more efficient way to request large data sets. This limit can be set by changing the [index.max_result_window] index level setting.
Read more »

计算文本相似度有多种方式,这里简单介绍一下其中的一种:词向量余弦。

词向量余弦

词向量余弦算法,是将文本作为一个多维空间的向量,计算两个文本的相识度即计算判断两个向量在这个多维空间中的方向是否是一样的。而这个多维空间的构成是通过将文本进行分词,每个分词代表空间的一个维度。

Read more »