parent
a2bbb59feb
commit
e6d3e03ac1
@ -0,0 +1,27 @@
|
|||||||
|
package com.mashibing.common.exception;
|
||||||
|
|
||||||
|
import com.mashibing.common.enums.ExceptionEnums;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 搜索模块的异常对象
|
||||||
|
* @author zjw
|
||||||
|
* @description
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
public class SearchException extends RuntimeException {
|
||||||
|
|
||||||
|
private Integer code;
|
||||||
|
|
||||||
|
public SearchException(String message, Integer code) {
|
||||||
|
super(message);
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public SearchException(ExceptionEnums enums) {
|
||||||
|
super(enums.getMsg());
|
||||||
|
this.code = enums.getCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package com.mashibing.push;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author zjw
|
||||||
|
* @description
|
||||||
|
*/
|
||||||
|
@SpringBootApplication
|
||||||
|
@EnableDiscoveryClient
|
||||||
|
public class PushStarterApp {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(PushStarterApp.class,args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
package com.mashibing.push.config;
|
||||||
|
|
||||||
|
import org.springframework.amqp.core.*;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author zjw
|
||||||
|
* @description
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class RabbitMQConfig {
|
||||||
|
|
||||||
|
public static final String DELAYED_EXCHANGE = "push_delayed_exchange";
|
||||||
|
|
||||||
|
public static final String DELAYED_QUEUE = "push_delayed_queue";
|
||||||
|
|
||||||
|
private static final String DELAYED_EXCHANGE_TYPE = "x-delayed-message";
|
||||||
|
|
||||||
|
private static final String DELAYED_ROUTING_TYPE_KEY = "x-delayed-type";
|
||||||
|
|
||||||
|
private static final String DELAYED_ROUTING_TYPE_FANOUT = "fanout";
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Exchange delayedExchange(){
|
||||||
|
Map<String, Object> args = new HashMap<>();
|
||||||
|
args.put(DELAYED_ROUTING_TYPE_KEY,DELAYED_ROUTING_TYPE_FANOUT);
|
||||||
|
Exchange delayedExchange = new CustomExchange(DELAYED_EXCHANGE,DELAYED_EXCHANGE_TYPE,false,false,args);
|
||||||
|
return delayedExchange;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Queue delayedQueue(){
|
||||||
|
return QueueBuilder.durable(DELAYED_QUEUE).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Binding delayedBinding(Exchange delayedExchange,Queue delayedQueue){
|
||||||
|
return BindingBuilder.bind(delayedQueue).to(delayedExchange).with("").noargs();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package com.mashibing.push.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author zjw
|
||||||
|
* @description
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class RestTemplateConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public RestTemplate restTemplate(){
|
||||||
|
return new RestTemplate();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
# 服务名称
|
||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: beacon-push
|
||||||
|
# 多环境
|
||||||
|
profiles:
|
||||||
|
active: dev
|
||||||
|
# nacos注册中心地址
|
||||||
|
cloud:
|
||||||
|
nacos:
|
||||||
|
discovery:
|
||||||
|
server-addr: 114.116.226.76:8848
|
||||||
|
# nacos配置中心地址:
|
||||||
|
config:
|
||||||
|
server-addr: 114.116.226.76:8848
|
||||||
|
file-extension: yml
|
||||||
|
# beacon-api-dev.yml
|
@ -0,0 +1,18 @@
|
|||||||
|
package com.mashibing.search;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author zjw
|
||||||
|
* @description
|
||||||
|
*/
|
||||||
|
@SpringBootApplication
|
||||||
|
@EnableDiscoveryClient
|
||||||
|
public class SearchStarterApp {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(SearchStarterApp.class,args);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package com.mashibing.search.service;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author zjw
|
||||||
|
* @description
|
||||||
|
*/
|
||||||
|
public interface SearchService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 向es中添加一行文档
|
||||||
|
* @param index 索引信息
|
||||||
|
* @param id 文档id
|
||||||
|
* @param json 具体的文档内容
|
||||||
|
*/
|
||||||
|
void index(String index,String id,String json) throws IOException;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
# 服务名称
|
||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: beacon-search
|
||||||
|
# 多环境
|
||||||
|
profiles:
|
||||||
|
active: dev
|
||||||
|
# nacos注册中心地址
|
||||||
|
cloud:
|
||||||
|
nacos:
|
||||||
|
discovery:
|
||||||
|
server-addr: 114.116.226.76:8848
|
||||||
|
# nacos配置中心地址:
|
||||||
|
config:
|
||||||
|
server-addr: 114.116.226.76:8848
|
||||||
|
file-extension: yml
|
||||||
|
# beacon-search-dev.yml
|
@ -0,0 +1,23 @@
|
|||||||
|
package com.mashibing.search.service;
|
||||||
|
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
public class SearchServiceTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SearchService searchService;
|
||||||
|
|
||||||
|
@org.junit.Test
|
||||||
|
public void index() throws IOException {
|
||||||
|
searchService.index("sms_submit_log_2023","3","{\"clientId\": 3}");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue