当前位置:   article > 正文

ElasticSearch搜不出来数据原因以及使用RabbitMQ出现问题和SpringBoot单体项目集成RabbitMQ_elasticsearch 搜索能连接上 不能搜索

elasticsearch 搜索能连接上 不能搜索

ElasticSearch搜不出来数据

原因:

  • 没有上线,没有保存在elasticSearch里面

  • 分词器的问题,搜索的单词没有被分词

  • 可能搜索的单词没有被分成一个词语,比如:java大神,分词成:java,大神。搜索 “java大”,就肯定搜索不出来。

  • 请求报错

  • 业务逻辑有问题,打断点跟踪。

- 使用RabbitMQ出现问题

  • 电脑用户名盘符是中文用户名

  • erlang环境安装出问题

- SpringBoot集成RabbitMQ

  • 导包
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
    </dependency>

    <!--spirngboot集成rabbitmq-->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-amqp</artifactId>
    </dependency>
</dependencies>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>2.0.5.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 配置yml连接参数
server:
  port: 8000
spring:
  application:
    name: rabbitmq
  rabbitmq:
    host: 127.0.0.1
    port: 5672
    username: guest
    password: guest
    virtualHost: /
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 对RabbitMQ作配置写一个配置类
@Configuration
public class RabbitMQConfig {
    //三个队列名字  短信 邮件 站内信
    //短信
    private static final String QUEUE_SMS = "queue_sms";
    //邮件
    private static final String QUEUE_EMAIL = "queue_email";
    //站内信
    private static final String QUEUE_SYSTEM = "queue_system";
    //交换机名称
    public static final String EXCHANGE_TOPIC = "exchange_topic";

    //定义交换机
    @Bean(EXCHANGE_TOPIC)
    public Exchange exchange() {
        return ExchangeBuilder.topicExchange(EXCHANGE_TOPIC).durable(true).build();
    }

    //定义邮件队列
    @Bean(QUEUE_EMAIL)
    public Queue queueEmail() {
        return new Queue(QUEUE_EMAIL, true);
    }

    //定义短信队列
    @Bean(QUEUE_SMS)
    public Queue queueSMS() {
        return new Queue(QUEUE_SMS, true);
    }

    //定义队列
    @Bean(QUEUE_SYSTEM)
    public Queue queueSystem() {
        return new Queue(QUEUE_SYSTEM, true);
    }
    //将队列绑定到交换机
    @Bean
    public Binding bindingEmail(@Qualifier(QUEUE_EMAIL) Queue queue,@Qualifier(EXCHANGE_TOPIC) Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("message_Email").noargs();
    }
    @Bean
    public Binding bindingSms(@Qualifier(QUEUE_SMS) Queue queue,@Qualifier(EXCHANGE_TOPIC) Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("message_Sms").noargs();
    }
    @Bean
    public Binding bindingSystem(@Qualifier(QUEUE_SYSTEM) Queue queue,@Qualifier(EXCHANGE_TOPIC) Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("message_System").noargs();
    }


}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 创建一个启动类
@SpringBootApplication
public class App {
    public static void main(String[] args) {
        SpringApplication.run(App.class,args);
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 发送消息
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
public class Send {
    @Autowired
    RabbitTemplate rabbitTemplate;
    @Test
    public void test() {
        for (int i = 0; i < 5; i++) {
            String message = "消息来了";
            rabbitTemplate.convertAndSend(RabbitMQConfig.EXCHANGE_TOPIC, "inform.sms.email");
            System.out.println(message);
        }
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 接收消息
@Component
public class Rev {
    //监听队列
    @RabbitListener(queues = RabbitMQConfig.QUEUE_EMAIL)
    public void listenter(String msg, Message message, Channel channel){
        System.out.println(msg);
    }
    //监听duilie
    @RabbitListener(queues = RabbitMQConfig.QUEUE_SYSTEM)
    public void listenter2(String msg,Message message,Channel channel){
        System.out.println(msg);
    }
    //监听队列
    @RabbitListener(queues = RabbitMQConfig.QUEUE_SMS)
    public void  listenter3(String msg,Message message,Channel
                            channel){
        System.out.println(msg);
    }

}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/942999
推荐阅读
相关标签
  

闽ICP备14008679号