2017-02-09 32 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應用程序?我無法想到的任何其他提示? 感謝任何輕

回答

相關問題