Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Rest控制器(RESTfulAPI)实现Spring云流消息传递系统(RabbitMQ)_Spring_Stream_Cloud - Fatal编程技术网

使用Rest控制器(RESTfulAPI)实现Spring云流消息传递系统(RabbitMQ)

使用Rest控制器(RESTfulAPI)实现Spring云流消息传递系统(RabbitMQ),spring,stream,cloud,Spring,Stream,Cloud,从过去几天开始,我尝试使用RestController实现springcloudstream消息传递系统,但在当前的实现中没有实现 对于这个示例代码,我将添加RestController 但是@InboundChannelAdapter无法接受来自RequestMappingGet方法URL的任何参数。最后,我需要的是使用Restful API Get Method from API调用向代理添加消息。哪一种是最好的方法呢?我无法从互联网上找到任何最好的流程。spring云团队已经提供了一个源

从过去几天开始,我尝试使用RestController实现springcloudstream消息传递系统,但在当前的实现中没有实现

对于这个示例代码,我将添加RestController

但是
@InboundChannelAdapter
无法接受来自
RequestMapping
Get方法URL的任何参数。最后,我需要的是使用Restful API Get Method from API调用向代理添加消息。哪一种是最好的方法呢?我无法从互联网上找到任何最好的流程。

spring云团队已经提供了一个源应用程序,用于侦听HTTP请求并将正文作为消息负载发送。如果内容类型与text/*或application/json匹配,则有效负载将是字符串,否则有效负载将是字节数组。

你可以这样做,或者如果你想自己写,你可以像下面这样做:

@RestController
@EnableBinding(Source.class)
public class RestSource {

    @Autowired
    private Source channels;

    @RequestMapping(path = "/", method = POST, consumes = {"application/json" })
    @ResponseStatus(HttpStatus.ACCEPTED)
    public void handleRequest(@RequestBody String body, @RequestHeader(HttpHeaders.CONTENT_TYPE) Object contentType) {
        sendMessage(body, contentType);
    }

    private void sendMessage(Object body, Object contentType) {
        channels.output().send(MessageBuilder.createMessage(body,
                new MessageHeaders(Collections.singletonMap(MessageHeaders.CONTENT_TYPE, contentType))));
    }
}

非常感谢你的回复。这真的帮了我很大的忙。以下url提供了使用spring与spring cloud集成的完整源和接收器开发=>
@RestController
@EnableBinding(Source.class)
public class RestSource {

    @Autowired
    private Source channels;

    @RequestMapping(path = "/", method = POST, consumes = {"application/json" })
    @ResponseStatus(HttpStatus.ACCEPTED)
    public void handleRequest(@RequestBody String body, @RequestHeader(HttpHeaders.CONTENT_TYPE) Object contentType) {
        sendMessage(body, contentType);
    }

    private void sendMessage(Object body, Object contentType) {
        channels.output().send(MessageBuilder.createMessage(body,
                new MessageHeaders(Collections.singletonMap(MessageHeaders.CONTENT_TYPE, contentType))));
    }
}