床架你消费者,接收写日志队列中的消息

main
heqijun 3 months ago
parent a747c8cb65
commit d513def487

@ -0,0 +1,41 @@
package com.mashibing.search.config;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @author heqijun
* @ClassName: RestHighLevelClient
* @Description: TODO()
* @date 2025/6/12 17:09
*/
@Configuration
public class RestHighLevelClientConfig {
@Value("${elasticsearch.hostAndPorts}")
private String[] hostAndPorts;
@Bean
public RestHighLevelClient restHighLevelClient() {
HttpHost[] httpHost = new HttpHost[hostAndPorts.length];
for (int i = 0; i < httpHost.length; i++) {
String[] hostAndPort = hostAndPorts[i].split(":");
httpHost[i] = new HttpHost(hostAndPort[0], Integer.parseInt(hostAndPort[1]));
}
RestClientBuilder restClientBuilder = RestClient.builder(httpHost);
RestHighLevelClient restHighLevelClient = new RestHighLevelClient(restClientBuilder);
return restHighLevelClient;
}
}

@ -0,0 +1,32 @@
package com.mashibing.search.mq;
import com.mashibing.common.constant.RabbitMQConstant;
import com.mashibing.common.pojo.StandardSubmit;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
import java.io.IOException;
/**
* @author heqijun
* @ClassName: SmsWriteLogListener
* @Description:
* @date 2025/6/12 17:31
*/
@Slf4j
@Component
public class SmsWriteLogListener {
@RabbitListener(queues = {RabbitMQConstant.SMS_WRITE_LOG})
public void process(StandardSubmit submit, Channel channel, Message message) throws IOException {
log.info("接收到存储日志的信息submit={}", submit);
//手动ack
channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
}
}
Loading…
Cancel
Save