spring-projects / spring-integration-extensions

The Spring Integration Extensions project provides extension components for Spring Integration
http://www.springintegration.org/
279 stars 265 forks source link

Can't configure channel for SmppInboundAdapter using @InboundChannelAdapter annotation #181

Closed KeithMilner closed 6 years ago

KeithMilner commented 6 years ago

I'm trying to configure an SmppInboundChannelAdapter using java config, and it doesn't let me configure the channel using the InboundChannelAdapter(value="fooChannel") annotation, which I understand to be the normal way of configuring these (see JdbcPollingChannelAdapter example at https://docs.spring.io/spring-integration/reference/html/overview.html ).

I've been able to configure it using the following:

@Bean
public SmppInboundChannelAdapter smppInboundChannelAdapter() {
    SmppInboundChannelAdapter smppInboundChannelAdapter = new SmppInboundChannelAdapter();
    try {
        smppInboundChannelAdapter.setSmppSession(smppSessionFactory().getObject());
        smppInboundChannelAdapter.setChannel(context.getBean("smsChannel", MessageChannel.class));
    } catch (Exception e) {
        e.printStackTrace();
    }
    return smppInboundChannelAdapter;
}

But this is rather ugly and it would be good if it could be configured using the annotation.

Looking at the adapter code, it appears to extend AbstractEndpoint and implement it's own "setChannel" method.

It would appear to be better to extend org.springframework.integration.endpoint.MessageProducerSupport instead, which provides methods for setOutputChannel, setOutputChannelName, etc. which appear to be what is expected by the annotation.

garyrussell commented 6 years ago

@InboundChannelAdapter is for polled endpoints; this is a message-driven endpoint.

Yes, it should be a MessageProducerSupport; however you can configure it a little more simply, like this...

@Bean
public SmppInboundChannelAdapter smppInboundChannelAdapter(MessageChannel smsChannel) {
    SmppInboundChannelAdapter smppInboundChannelAdapter = new SmppInboundChannelAdapter();
    try {
        smppInboundChannelAdapter.setSmppSession(smppSessionFactory().getObject());
        smppInboundChannelAdapter.setChannel(smsChannel);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return smppInboundChannelAdapter;
}
KeithMilner commented 6 years ago

OK, thanks. Is there an equivalent annotation for message driven endpoints, out of interest?

garyrussell commented 6 years ago

No; they are simple @Beans; polled endpoints need two beans a SourcePollingChannelAdapter and a MessageSource; the annotation causes the framework to create the SPCA and a MessageSource wrapper around the source method.

artembilan commented 6 years ago

??? There is no reason for that annotation because MessageProducer is a thing per se: https://docs.spring.io/spring-integration/reference/html/overview.html#programming-tips.

There is just no need to auto-configured some infrastructure around this type of components, like in case of pollable Channel Adapters.

KeithMilner commented 6 years ago

OK, thanks

garyrussell commented 6 years ago

INTEXT-230.