Я пытаюсь реализовать spring -boot-integration-smpp, но получаю исключение с нулевым указателем.
интеграция-context.xml
<!--smpp integration-->
<int-smpp:outbound-gateway
id = "smppIntegrationOutboundGateway"
request-channel = "toSMPPChannel"
source-address = "Indosat"
smpp-session-ref = "smppSession"
reply-channel = "fromSMPPChannel"/>
<int:service-activator ref = "printService" method = "print" input-channel = "fromSMPPChannel">
<int:poller fixed-delay = "1"/>
</int:service-activator>
<int:gateway id = "smsGateway" service-interface = "com.omexit.niger.smsworker.service.SMSGateway" default-request-channel = "toSMPPChannel"/>
<!-- connect to the local broker using the default user name and password -->
<bean id = "rabbitConnectionFactory" class = "org.springframework.amqp.rabbit.connection.CachingConnectionFactory">
<constructor-arg value = "${spring.rabbitmq.host}"/>
<constructor-arg value = "${spring.rabbitmq.port}"/>
<property name = "username" value = "${spring.rabbitmq.username}"/>
<property name = "password" value = "${spring.rabbitmq.password}"/>
</bean>
<bean id = "smppSession" class = "org.springframework.integration.smpp.session.SmppSessionFactoryBean">
<property name = "host" value = "xxxx"/>
<property name = "port" value = "xx"/>
<property name = "systemId" value = "LBS1"/>
<property name = "password" value = "Bsl04n1"/>
<property name = "systemType" value = "TCP"/>
<property name = "addrTon" value = "INTERNATIONAL"/>
<property name = "addrNpi" value = "ISDN"/>
<property name = "autoStartup" value = "true"/>
</bean>
Отправить сообщение
System.err.println(strMessage);
Message<String> message = MessageBuilder.withPayload(strMessage)
.setHeader(SmppConstants.SRC_ADDR, "xyz")
.setHeader(SmppConstants.DST_ADDR, "6285781029162")
.setHeader(SmppConstants.REGISTERED_DELIVERY_MODE, SMSCDeliveryReceipt.SUCCESS)
.build();
String res = (String) smsGateway.send(message).getPayload();
System.err.println("Res: " +res);
Исключение:
2018-11-27 14:56:21.414 ERROR [-,,,] 24620 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.integration.smpp.outbound.SmppOutboundGateway#0': Invocation of init method failed; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1745) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:576) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:846) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:863) ~[spring-context-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546) ~[spring-context-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at com.mode.indosat.smsworker.SmsWorkerApplication.main(SmsWorkerApplication.java:31) [classes/:na]
Caused by: java.lang.NullPointerException: null
at org.springframework.integration.smpp.session.SmppSessionFactoryBean$AutoReconnectLifecycle.scheduleReconnect(SmppSessionFactoryBean.java:548) ~[spring-integration-smpp-1.0.0.RELEASE.jar:na]
at org.springframework.integration.smpp.session.SmppSessionFactoryBean$AutoReconnectLifecycle.start(SmppSessionFactoryBean.java:487) ~[spring-integration-smpp-1.0.0.RELEASE.jar:na]
at org.springframework.integration.smpp.session.ExtendedSmppSessionAdaptingDelegate.start(ExtendedSmppSessionAdaptingDelegate.java:78) ~[spring-integration-smpp-1.0.0.RELEASE.jar:na]
at org.springframework.integration.smpp.outbound.SmppOutboundGateway.doInit(SmppOutboundGateway.java:62) ~[spring-integration-smpp-1.0.0.RELEASE.jar:na]
at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.onInit(AbstractReplyProducingMessageHandler.java:94) ~[spring-integration-core-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.integration.context.IntegrationObjectSupport.afterPropertiesSet(IntegrationObjectSupport.java:178) ~[spring-integration-core-5.1.0.RELEASE.jar:5.1.0.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1804) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1741) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
... 16 common frames omitted
Похоже на ошибку в SmppOutboundGateway: мы не можем запустить session так рано из onInit(). Пожалуйста, поднимите вопрос против проекта https://github.com/spring-projects/spring-integration-extensions.
Между тем, в качестве обходного пути вы можете ввести свойство reconnectingExecutor в SmppSessionFactoryBean:
<bean id = "smppSession" class = "org.springframework.integration.smpp.session.SmppSessionFactoryBean">
<property name = "host" value = "xxxx"/>
<property name = "port" value = "xx"/>
<property name = "systemId" value = "LBS1"/>
<property name = "password" value = "Bsl04n1"/>
<property name = "systemType" value = "TCP"/>
<property name = "addrTon" value = "INTERNATIONAL"/>
<property name = "addrNpi" value = "ISDN"/>
<property name = "autoStartup" value = "true"/>
<property name = "reconnectingExecutor" ref = "reconnectingExecutorService"/>
</bean>
Я добавил ваше определение bean-компонента SmppSessionFactoryBean к своему ответу со свойством reconnectingExecutor в конце. Это теперь ясно?
Я получаю следующую ошибку. org.springframework.beans.factory.BeanCreationException: Ошибка при создании bean-компонента с именем smppIntegrationOutboundGateway: не удалось вызвать метод инициализации; вложенное исключение - java.lang.IllegalArgumentException: для конечной точки smppIntegrationOutboundGateway не определен опросчик, и опрос по умолчанию недоступен в контексте. ... Вызвано: java.lang.IllegalArgumentException: для конечной точки smppIntegrationOutboundGateway не определен опросчик, и опрос по умолчанию недоступен в контексте
Это другая история. Ваш toSMPPChannel представляет собой очередь, и его подписчик не может остаться без опросчика. Или вы должны определить глобальный по умолчанию. Пожалуйста, проконсультируйтесь с Документами по этому поводу.
Я согласен. Я уже определил глобальный опросчик, и исходящий шлюз не принимает опросчик
Решает ли это вашу проблему? Пришло ли время подумать о том, чтобы принять ответ, чтобы закрыть обсуждение помощи другим в сообществе?
Не совсем понимаю, как добавить повторное подключениеExecutorService. Я пробовал следующее, но не работает:
@Bean(name = "reconnectingExecutorService") public ExecutorService executorService(){ return Executors.newSingleThreadExecutor(); }