2010-03-25 3 views
3

MessageChannel 앞에 큐를 연결하려고 시도 했으므로 프로그래밍 방식으로 수행해야 osgi:listener 트리거에 대한 응답으로 런타임에이를 수행 할 수 있습니다. 지금까지 내가 가지고 : 프로그래밍 방식으로 Spring의 MessageChannel에 QueueChannel 브리징

public void addService(MessageChannel mc, Map<String,Object> properties) 
{ 
    //Create the queue and the QueueChannel 
    BlockingQueue<Message<?>> q = new LinkedBlockingQueue<Message<?>>(); 
    QueueChannel qc = new QueueChannel(q); 

    //Create the Bridge and set the output to the input parameter channel 
    BridgeHandler b = new BridgeHandler(); 
    b.setOutputChannel(mc); 

    //Presumably, I need something here to poll the QueueChannel 
    //and drop it onto the bridge. This is where I get lost 

} 

가 다양한 관련 클래스를 통해 찾고, 내가 해낸 :

PollerMetadata pm = new PollerMetadata(); 
    pm.setTrigger(new IntervalTrigger(10)); 

    PollingConsumer pc = new PollingConsumer(qc, b); 

하지만 난 모두 함께 넣을 수 아니에요. 내가 뭘 놓치고 있니?

답변

0

그래서, 나를 위해 일하는 결국 해결책이었다 :

public void addEngineService(MessageChannel mc, Map<String,Object> properties) 
{ 
    //Create the queue and the QueueChannel 
    BlockingQueue<Message<?>> q = new LinkedBlockingQueue<Message<?>>(); 
    QueueChannel qc = new QueueChannel(q); 

    //Create the Bridge and set the output to the input parameter channel 
    BridgeHandler b = new BridgeHandler(); 
    b.setOutputChannel(mc); 

    //Setup a Polling Consumer to poll the queue channel and 
    //retrieve 1 thing at a time 
    PollingConsumer pc = new PollingConsumer(qc, b); 
    pc.setMaxMessagesPerPoll(1); 

    //Now use an interval trigger to poll every 10 ms and attach it 
    IntervalTrigger trig = new IntervalTrigger(10, TimeUnit.MILLISECONDS); 
    trig.setInitialDelay(0); 
    trig.setFixedRate(true); 
    pc.setTrigger(trig); 

    //Now set a task scheduler and start it 
    pc.setTaskScheduler(taskSched); 
    pc.setAutoStartup(true); 
    pc.start(); 
} 

나는 위의 모든 명시 적으로 필요한 경우 정말 분명 아니지만, 트리거 또는 작업 스케줄러도 혼자 일을, 내가 그랬어 둘 다 필요해 보입니다. 나는 또한 작업을주의해야한다. 사용 된 기본 작업은 봄철부터 분사되는 스케쥴러 종속성이다.

<property name="taskSched" ref="taskScheduler"/>