в моем проекте я должен получить сообщение (Json) от моего потребителя в "topic1", и оно работает хорошо. После того, как я должен обработать это сообщение с помощью функции my, и после записи True или False в "topic2" в Producer на том же брокере.
мой класс Consumer: CONSUMER CLASS
@Configuration
public class Consumer {
private static final Logger logger = LoggerFactory.getLogger(Consumer.class);
@Autowired MqttPahoClientFactory mqttClientFactory;
@Autowired Producer producer;
@Bean
public MessageChannel topicChannel(){
return new DirectChannel();
}
@Bean
public MessageProducer mqttInbound() {
MqttPahoMessageDrivenChannelAdapter adapter = new MqttPahoMessageDrivenChannelAdapter(
Parameters.MQTT_CLIENT_ID, mqttClientFactory, Parameters.TOPICS[0]);
adapter.setCompletionTimeout(5000);
adapter.setConverter(new DefaultPahoMessageConverter());
adapter.setQos(1);
adapter.setOutputChannel(topicChannel());
return adapter;
}
@Bean
@ServiceActivator(inputChannel = "topicChannel")
public MessageHandler handler() {
return message -> {
OduModel model = JsonUtility.convertToOduModel(String.valueOf(message.getPayload()));
logger.info(model.toString());
boolean condition = DataProcessor.processOduModel(model);
logger.info(String.valueOf(condition));
ApplicationContext context = new SpringApplicationBuilder(Producer.class).context(); <--- context here is null;
**Producer.ProducerGateway gw = context.getBean(Producer.ProducerGateway.class);** <---- Here I have ERROR and i cant getBean on Producer...
if (condition){
gw.sendToMqtt("OK", Parameters.TOPICS[2]);
}
else{
gw.sendToMqtt("NON OK", Parameters.TOPICS2]);
}
};
}
}
PRODUCER CLASS :
@Configuration
public class Producer {
@Autowired MqttPahoClientFactory mqttClientFactory;
@Bean
public MessageChannel mqttOutboundChannel(){
return new DirectChannel();
}
@MessagingGateway(defaultRequestChannel = "mqttOutboundChannel")
public interface ProducerGateway {
void sendToMqtt(String data, @Header(MqttHeaders.TOPIC) String topic);
}
@Bean
@ServiceActivator(inputChannel = "mqttOutboundChannel")
public MessageHandler mqttOutbound() {
MqttPahoMessageHandler messageHandler = new MqttPahoMessageHandler(
Parameters.MQTT_CLIENT_ID,
mqttClientFactory);
messageHandler.setAsync(true);
messageHandler.setLoggingEnabled(true);
return messageHandler;
}
}
Я не могу получить Bean ProducerGateway на Producer, почему контекст нулевой, почему? с уважением