spring kafka,MessageDeliveryException:无法向通道发送消息

时间:2017-09-22 02:08:30

标签: spring-cloud-stream spring-kafka

我正在努力解决有关源,进程和接收器的问题。我有两个项目,申请。一个用于源,另一个用于进程和接收。

让我分享每个组件以弄清楚发生了什么。

@EnableBinding(MultiProducerChannel.class)
public class RealTimeDataSource{

@Autowired
RealTimeProductionService realTimeProductionService;

@InboundChannelAdapter(value = MultiProducerChannel.SOURCEPRODUCTION, poller = @Poller(fixedDelay = "10000", maxMessagesPerPoll = "1"))
public JSONArray productionMessageSource() throws Exception {

    long currentTime = System.currentTimeMillis();

    JSONArray realTimeProductionList = realTimeProductionService.getNewProductionTime();

    System.out.println(currentTime + " : Running source...");
    return realTimeProductionList;

    }

}


@EnableBinding(MultiChannel.class)
public class RealTimeDataProcessor {

@Autowired
RealTimeProductionService realTimeProductionService;

@Transformer(inputChannel = MultiChannel.PROCESSPRODUCTION, outputChannel = MultiChannel.SAVEPRODUCTION)
public JSONObject productionMessageProcessor(List<RealTimeProduction> realTimeProductionList) throws Exception {

    JSONObject jsonObject = null;
    if(realTimeProductionList != null) {
        jsonObject = new JSONObject(realTimeProductionService.getNewProductionTime(realTimeProductionList));
        System.out.println("PROCESSOR RUNNING...");
    }

    return jsonObject;
    }
}

@EnableBinding(MultiChannel.class)
public class RealTimeDataSink {

private static final String INDEX_NAME = "c000001_kr_50879_f01";


@Autowired
private JestClient jestClient;

@StreamListener(MultiChannel.SAVEFINALPRODUCTION)
public void productionMessageSink(JSONObject outputs) throws Exception {

    if (outputs != null) {

        boolean indexExists = jestClient.execute(new IndicesExists.Builder(INDEX_NAME).build()).isSucceeded();

        JestResult jestResult = jestClient.execute(new Index.Builder(outputs).index(INDEX_NAME).type("production").build());




        System.out.println("SINK RUNNING...");

    }
}

}

   public interface MultiChannel {

String SOURCEPRODUCTION = "production-source";

String PROCESSPRODUCTION = "production-process";

String SAVEPRODUCTION = "production-save";

String SAVEFINALPRODUCTION = "production-save-final";

@Output(SOURCEPRODUCTION)
MessageChannel sourceproduction();

@Input(PROCESSPRODUCTION)
SubscribableChannel processorproduction();

@Output(SAVEPRODUCTION)
MessageChannel saveproduction();

@Input(SAVEFINALPRODUCTION)
SubscribableChannel savefinalproduction();

}

我觉得这个源很好用。但我不知道如何找到有关此错误的问题。我整整花了三天......仍然......不是那个人。

org.springframework.messaging.MessageDeliveryException: failed to send Message to channel 'production-save'; nested exception is java.lang.IllegalArgumentException: payload must not be null

对此有何看法?

1 个答案:

答案 0 :(得分:1)

考虑使用@StreamListener@SendTo代替@Transformer进行自动内容类型处理:https://docs.spring.io/spring-cloud-stream/docs/Ditmars.RC1/reference/htmlsingle/#_using_streamlistener_for_automatic_content_type_handling

如果这无法考虑为contentType: application/json绑定配置production-savehttps://docs.spring.io/spring-cloud-stream/docs/Ditmars.RC1/reference/htmlsingle/#_properties_for_use_of_spring_cloud_stream