英文:
Quartz service is not working using Spring Feign Client
问题
我使用 Spring Quartz 库创建了实时通知功能。我创建了两个服务如下:
- quartz-service:用于设置实时通知的计划。
- task-service:用于创建任务并通过 quartz-service 进行提醒。
当 task-service 通过 Feign 客户端调用 quartz-service 时,我没有收到任何响应。但是如果我通过 Rest Template 调用,它正常工作。
实际上,我们使用了 Spring Boot 微服务架构,在使用 Rest Template 时,我们需要指定硬编码的 URL,因此在这种情况下我们无法实现 Ribbon 概念,这就是为什么我们不希望使用 Rest Template。
因此,请帮助我,如果有人遇到过这个问题。
quartz-service:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-quartz</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
Rest Controller:
@RestController
@RequestMapping(value = "/quartz/taks", produces = "application/hal+json")
public class QuartzTaskController
{
@Autowired
private QuartzTaskServices quartzTaskServices;
@PostMapping("/reminder")
public ResponseEntity<Object> saveTaskReminder(@RequestBody Task task)
{
quartzTaskServices.saveTaskReminderScheduler(task);
return ResponseEntity.ok().build();
}
}
task-service
依赖项:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
</dependency>
Feign 客户端:
@RibbonClient(name="quartz-services")
@FeignClient(name="quartz-services")
public interface QuartzProxy
{
@PostMapping("/quartz/taks/reminder")
public ResponseEntity<Object> saveTaskReminder(@RequestBody Task task);
}
调用 Feign 客户端:
@Autowired
private QuartzProxy quartzProxy;
...
......
......
quartzProxy.saveTaskReminder(task);
英文:
I create a real time notification functionality using spring quartz library. I create two services as bellow :
- quartz-service : Which is used to set schedule a for real time notification.
- task-service : Which is used to create a task and remind through quartz-service.
When task-service call quartz-service through feign client I'm not get any response. But If I call through Rest Template it's working find.
Actually we are used spring boot microservice architecture, In using Rest Template we need to specify URL Hard coded, So we can't achieved Ribbon concept in this case that's why we not interest to use Rest Template.
So please help me if any once face this problem.
quartz-service :
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-quartz</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
Rest Controller :
@RestController
@RequestMapping(value = "/quartz/taks", produces = "application/hal+json")
public class QuartzTaskController
{
@Autowired
private QuartzTaskServices quartzTaskServices;
@PostMapping("/reminder")
public ResponseEntity<Object> saveTaskReminder(@RequestBody Task task)
{
quartzTaskServices.saveTaskReminderScheduler(task);
return ResponseEntity.ok().build();
}
}
task-service
Dependency :
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
</dependency>
Feign Client :
@RibbonClient(name="quartz-services")
@FeignClient(name="quartz-services")
public interface QuartzProxy
{
@PostMapping("/quartz/taks/reminder")
public ResponseEntity<Object> saveTaskReminder(@RequestBody Task task);
}
Call Feign Client :
@Autowired
private QuartzProxy quartzProxy;
...
.....
......
quartzProxy.saveTaskReminder(task);
专注分享java语言的经验与见解,让所有开发者获益!
评论