2017-02-09 71 views
0

我想知道是否可以调用流源而不是轮询。 我的来源是这样的(行不通):Spring Cloud Stream - 编程式发布

@SpringBootApplication 
@RestController 
@EnableBinding(Source.class) 
public class ServiceApplication { 
    private final Logger logger = LoggerFactory.getLogger(this.getClass()); 

    public static void main(String[] args) { 
     SpringApplication.run(ServiceApplication.class, args); 
    } 

    @Autowired 
    private PersonsRepository dao; 

    @GetMapping("/send") 
    public String sendMessage() { 
     this.sendVoter("foo"); 
     return "VOTER SENT"; 
    } 

    @SentTo(Source.OUTPUT) 
    private Person sendVoter(String name) { 
     logger.warn("Sending..."); 
     return dao.findByFirstname(name); 
    } 
} 

为了使它开始,我不得不代码:

@SpringBootApplication 
@RestController 
@EnableBinding(Source.class) 
public class ServiceApplication { 
... 
    @GetMapping("/send") 
    public String sendMessage() { 
     this.sendVoter(); 
     return "VOTER SENT"; 
    } 

    @InboundChannelAdapter(Source.OUTPUT) 
    private Person sendVoter() { 
     logger.warn("Sending..."); 
     return dao.findByFirstname("foo"); 
    } 
} 

但来源开始的时候了。它不是以编程方式触发的。 我是否必须使用ApplicationEventPublisher,还是仅针对Spring Cloud Bus应用程序?我无法想到的任何其他提示? 感谢任何轻

回答

相关问题