Программно соединить QueueChannel с MessageChannel весной - PullRequest
3 голосов
/ 26 марта 2010

Я пытаюсь подключить очередь к передней части MessageChannel, и мне нужно сделать это программно, чтобы сделать это во время выполнения в ответ на срабатывание osgi:listener. Пока у меня есть:

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);

но я не могу собрать все это вместе. Чего мне не хватает?

1 Ответ

0 голосов
/ 05 апреля 2010

Итак, решение, которое закончилось для меня, было:

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();
}

Мне не очень понятно, если все вышеперечисленное явно необходимо, но ни триггер, ни планировщик задач не работали, мне, кажется, нужны были оба. Я также должен отметить, что taskSched был зависимостью taskScheduler по умолчанию, внедренной из весны через

<property name="taskSched" ref="taskScheduler"/>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...