使用REST Web服务传达2个修改应用程序



我有两个应用程序,在第一个应用程序中,我设置了操作,如果设置了操作,我必须将其数据发送到REST WEBS服务并在第二个应用程序中启动方法。我不知道用户何时要在第1个操作内设置操作的问题,因此我应该始终发送请求以查看操作是否设置。

在第一个应用中

  @RequestMapping("/add")
public void  setSomething(){
    final String uri = "http://localhost:8080/from";
    Greeting greeting = new Greeting(3,"Send to the other App");
    System.out.println("======================>>"+greeting.getContent());
    RestTemplate restTemplate = new RestTemplate() ;
    Greeting result= restTemplate.postForObject( uri,greeting, Greeting.class);
}

在第二个应用程序中:

  @RequestMapping(value = "/from", method = RequestMethod.POST)
public ResponseEntity<String> createEmployee(@RequestBody Greeting greeting)
{
    return new ResponseEntity(HttpStatus.ACCEPTED);
}

它正在工作,问候被发送到另一个应用程序,但是当我将问候转换为另一个值时,问题始终记住第一个值,因此不采用mdofication

"当用户要在第一个操作内设置操作时"。当这种情况发生时,您的第一个操作中的代码称为正确吗?那么,为什么不只是在第二个应用中调用休息端点来触发所需的过程。

Application 1 :
 If(operationSet){
SendRequestToREST(operation)
notifyApp2()// if your app 2 has rest endpoint you can use RestTemplate
}
Application 2 :
 ListenToRest();
if(operationIsSet){
doSomething()
}

或您的架构包含2个以上的应用程序。只要告诉我们,我们将发明其他解决方案的消息队列Amazonsns免费服务。但是,如果仅在2个实例之间进行交流 - 此解决方案就足够

您询问第一个App1如何通知第二个App2。您建议的App2是否设置了参数,请检查App1。但是现在使用该解决方案,您可以在需要的那一刻通知。

//I am app1
public void  notifyApp2(){
    final String uri = "http://localhost:8080/from";
    Greeting greeting = new Greeting(3,"Send to the other App");
    System.out.println("======================>>"+greeting.getContent());
    RestTemplate restTemplate = new RestTemplate() ;
    Greeting result= restTemplate.postForObject( uri,greeting, Greeting.class);
}

  @RequestMapping(value = "/from", method = RequestMethod.POST)
public ResponseEntity<String> createEmployee()
{
    //I am app2 and someone is calling my rest. I am being notified.
    //maybe they notify me to set my operations setOperation=true;
return new ResponseEntity(HttpStatus.ACCEPTED);

}

现在让我们假设用户与App1一起工作。从App1调用方法setOperationInapp1时,您只需在下一行上调用notifyapp2((即可。您将在两个应用程序上设置操作

最新更新