重 REST 应用程序
Heavy REST Application
我有一个企业服务总线 (ESB),它 post 通过 Rest 将数据传输到微服务 (MCS)。我使用 Spring 来做到这一点。主要问题是我有 6 个微服务,一个接一个 运行。所以它看起来像这样:MCS1 -> ESB -> MCS2 -> ESB -> ... -> MCS6
所以我的问题是这样的:(ESB)
@RequestMapping(value = "/rawdataservice/container", method = RequestMethod.POST)
@Produces(MediaType.APPLICATION_JSON)
public void rawContainer(@RequestBody Container c)
{
// Here i want to do something to directly send a response and afterwards execute the
// heavy code
// In the heavy code is a postForObject to the next Microservice
}
服务会做这样的事情:
@RequestMapping(value = "/container", method = RequestMethod.POST)
public void addDomain(@RequestBody Container container)
{
heavyCode();
RestTemplate rt = new RestTemplate();
rt.postForObject("http://134.61.64.201:8080/rest/rawdataservice/container",container, Container.class);
}
但是我不知道该怎么做。我查找了 post 的 Location 方法,但我认为它不能解决问题。
编辑:
我有一个微服务链。第一个微服务等待 ESB 的响应。在响应中,ESB post 发送到另一个微服务并等待响应,下一个与第一个微服务做同样的事情。所以问题是只要完整的微服务路由完成,第一个微服务就会被阻塞。
ESB Route
也许一张照片会有所帮助。 1.rawdataService 2.metadataservice 3.syntaxservice 4.semantik
// Here i want to do something to directly send a response and afterwards execute the
// heavy code
通常的拼写是使用来自 http 请求的数据创建一个知道如何完成工作的 Runnable,并将该 runnable 分派给执行程序服务以供以后处理。大致相同,您将需要的数据复制到 queue 中,其他线程会轮询该数据以完成工作。
一旦执行程序 service/queue 接受了挂起的工作,http 请求处理程序就会 return 启动。最常见的实现是 return 一个“202 已接受”响应,包括在位置 header 中 url 的资源,如果需要,该资源将允许客户端监视正在进行的工作.
在Spring中,可能是ResponseEntity为您管理代码。例如
ResponseEntity.accepted()....
另请参阅:
- How to respond with HTTP 400 error in a Spring MVC @ResponseBody method returning String?
- REST - Returning Created Object with Spring MVC
从调用者的角度来看,它会调用 RestTemplate.postForLocation
,接收 URI,然后丢弃该 URI,因为微服务只需要知道工作已被接受
旁注:从长远来看,您可能希望能够关联不同微服务的活动,尤其是在进行故障排除时。因此,请确保您了解 Gregor Hohpe 对 correlation identifiers.
的看法
我有一个企业服务总线 (ESB),它 post 通过 Rest 将数据传输到微服务 (MCS)。我使用 Spring 来做到这一点。主要问题是我有 6 个微服务,一个接一个 运行。所以它看起来像这样:MCS1 -> ESB -> MCS2 -> ESB -> ... -> MCS6
所以我的问题是这样的:(ESB)
@RequestMapping(value = "/rawdataservice/container", method = RequestMethod.POST)
@Produces(MediaType.APPLICATION_JSON)
public void rawContainer(@RequestBody Container c)
{
// Here i want to do something to directly send a response and afterwards execute the
// heavy code
// In the heavy code is a postForObject to the next Microservice
}
服务会做这样的事情:
@RequestMapping(value = "/container", method = RequestMethod.POST)
public void addDomain(@RequestBody Container container)
{
heavyCode();
RestTemplate rt = new RestTemplate();
rt.postForObject("http://134.61.64.201:8080/rest/rawdataservice/container",container, Container.class);
}
但是我不知道该怎么做。我查找了 post 的 Location 方法,但我认为它不能解决问题。
编辑: 我有一个微服务链。第一个微服务等待 ESB 的响应。在响应中,ESB post 发送到另一个微服务并等待响应,下一个与第一个微服务做同样的事情。所以问题是只要完整的微服务路由完成,第一个微服务就会被阻塞。
ESB Route 也许一张照片会有所帮助。 1.rawdataService 2.metadataservice 3.syntaxservice 4.semantik
// Here i want to do something to directly send a response and afterwards execute the
// heavy code
通常的拼写是使用来自 http 请求的数据创建一个知道如何完成工作的 Runnable,并将该 runnable 分派给执行程序服务以供以后处理。大致相同,您将需要的数据复制到 queue 中,其他线程会轮询该数据以完成工作。
一旦执行程序 service/queue 接受了挂起的工作,http 请求处理程序就会 return 启动。最常见的实现是 return 一个“202 已接受”响应,包括在位置 header 中 url 的资源,如果需要,该资源将允许客户端监视正在进行的工作.
在Spring中,可能是ResponseEntity为您管理代码。例如
ResponseEntity.accepted()....
另请参阅:
- How to respond with HTTP 400 error in a Spring MVC @ResponseBody method returning String?
- REST - Returning Created Object with Spring MVC
从调用者的角度来看,它会调用 RestTemplate.postForLocation
,接收 URI,然后丢弃该 URI,因为微服务只需要知道工作已被接受
旁注:从长远来看,您可能希望能够关联不同微服务的活动,尤其是在进行故障排除时。因此,请确保您了解 Gregor Hohpe 对 correlation identifiers.
的看法