xxl-job整合到consul,openfeign实现接口调用

1.下载xxl-job

2.修改xxl-job执行器application配置文件,添加如下内容:

spring.application.name=meeting-job
spring.cloud.consul.host=127.0.0.1
spring.cloud.consul.port=8500
spring.cloud.consul.discovery.health-check-interval=8s
spring.cloud.consul.discovery.prefer-ip-address=true
spring.cloud.consul.discovery.ip-address=${base.url}
spring.cloud.consul.discovery.health-check-path=${server.servlet.context-path}/actuator/health
spring.main.allow-bean-definition-overriding=true

3.修改xxl-job执行器pom配置文件,添加如下内容:

<!-- consul注册中心 -->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-consul-discovery</artifactId>
    <version>2.2.1.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
    <version>2.2.6.RELEASE</version>
</dependency>
<!-- ribbon -->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
    <version>2.2.1.RELEASE</version>
</dependency>

<!--openfeign-->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-openfeign</artifactId>
    <version>2.2.1.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpclient</artifactId>
</dependency>

4.启动类XxlJobExecutorApplication添加配置,如下:

@EnableFeignClients
@EnableDiscoveryClient

5.添加FeignConfig类,如下:

@Configuration
public class FeignConfig {
    /**
     *No qualifying bean of type ‘org.springframework.boot.autoconfigure.http.HttpMessage
     */
    @Bean
    @ConditionalOnMissingBean
    public HttpMessageConverters messageConverters(ObjectProvider<HttpMessageConverter<?>> converters) {
        return new HttpMessageConverters(converters.orderedStream().collect(Collectors.toList()));
    }
}

6.创建feign调用接口类,如下所示:

@FeignClient(name = "meeting-web", path = "/meeting/v1/service/device", configuration = FeignHeadConfiguration.class)
public interface DeviceService {

    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    void insert(@RequestBody Device device);

    @RequestMapping(value = "/update", method = RequestMethod.POST)
    void update(@RequestBody Device device);

    @RequestMapping(value = "/getCount", method = RequestMethod.GET)
    int getCount(@RequestParam(value = "acsDevIndexCode") String acsDevIndexCode);

}

7.服务提供者,如下:

@RestController
@RequestMapping(value = "/v1/service/device")
@CrossOrigin
public class DeviceApi {
    @Autowired
    private DeviceService deviceService;

    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public void insert(@RequestBody Device device) {
        deviceService.insert(device);
    }

    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public void update(@RequestBody Device device) {
        deviceService.update(device);
    }

    @RequestMapping(value = "/getCount", method = RequestMethod.GET)
    public int getCount(@RequestParam(value = "acsDevIndexCode") String acsDevIndexCode) {
        return deviceService.getCount(acsDevIndexCode);
    }

}

8.执行器里面执行调用,如下图所示:

 9. 启动执行器,大功告成。

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值