代码之家  ›  专栏  ›  技术社区  ›  Deepboy

在Spring集成中将'application.errorChannel'添加到配置中

  •  0
  • Deepboy  · 技术社区  · 6 年前

    我已经编写了一个程序来读取安慰队列中的消息。我得到下面的错误。

    你能帮忙吗?

    enter image description here 代码如下:

    我的主要配置如下:

    public class ReadFromQueueConfig {
    
        @Autowired
        private PrintMessageFromQueue printMessageFromQueue;
    
        String queueName = "MY.SAMPLE.SOLACE.QUEUE";
    
        @Bean
        public CachingConnectionFactory jmsConnectionFactory() {
            CachingConnectionFactory ccf = new CachingConnectionFactory();
            try {
                SolConnectionFactory scf = SolJmsUtility.createConnectionFactory();
                scf.setHost("host");
                scf.setUsername("username");
                scf.setVPN("vpm");
                scf.setPassword("password");
                scf.setDirectTransport(false);
    
                ccf.setTargetConnectionFactory(scf);
    
            } catch (Exception e) {
                logger.debug(e.getMessage());
            }
            return ccf;
        }
    
        @Bean
        public IntegrationFlow handleJsmInput() {
            return IntegrationFlows
                    .from(Jms.inboundAdapter(jmsConnectionFactory()).destination(queueName))
                            .handle(printMessageFromQueue)
                            .get();
        }
    }
    

    printmessagefromqueue.java: enter image description here

    更新: 我的主要课程:

    @SpringBootApplication
    @EnableIntegration
    @IntegrationComponentScan
    public class TestReadFromQueueApplication {
        public static void main(String[] args) {
            SpringApplication.run(TestReadFromQueueApplication.class, args);
        }
    }
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   Artem Bilan    6 年前

    你可以在 main() 在创建 ApplicationContext :

    final Scanner scanner = new Scanner(System.in);
    context.close();
    

    因此,在控制台中输入一些信息之前,应用程序不会退出。

    此外,您还可以等待消息被使用,例如通过 QueueChannel.receive() . 一些样本阻止A main 在Apache Kafka示例中完成的Spring集成示例中: https://github.com/spring-projects/spring-integration-samples/blob/master/basic/kafka/src/main/java/org/springframework/integration/samples/kafka/Application.java