Quantcast
Channel: Active questions tagged propagation - Stack Overflow
Viewing all articles
Browse latest Browse all 54

Services not synchronized Spring

$
0
0

I'm currently facing an issue which I'm unable to solve.

Here the problem.I have a class Picker inside Microservice PickerManager that requires services. This Picker class sends events via RabbitMQ to Microservice B.

@Componentclass Picker {    @Autowired    public Picker(Services services,                  ApplicationEventPublisher eventPublisher,                  UtilsPickerManager utilsPickerManager,                  UtilsAW utilsAW) throws Exception {        this.services = services;        this.eventPublisher = eventPublisher;    }    private PickerCommandEO movePickerToTargetSegment() {        // ... code        eventPublisher.publishEvent(commands.get(0).getEvent()); // <- Send an event        // ... code    }}

Sending this event invokes the following method:

@Componentpublic class DriverCommandSenderImpl {    private static final Logger LOGGER = LoggerFactory.getLogger(DriverCommandSenderImpl.class);    private final String exchangeName;    private final AmqpTemplate amqpTemplate;    DriverCommandSenderImpl(@Value("${corren.driver.pickers.commands.exchange-name}") String exchangeName, AmqpTemplate amqpTemplate) {        this.exchangeName = exchangeName;        this.amqpTemplate = amqpTemplate;    }    @EventListener    public void onPickerCommand(PickerCommand mo) {        final Gson gson = new GsonBuilder().create();        String moAsString = gson.toJson(mo);        try {            amqpTemplate.convertAndSend(exchangeName, "csa.commands."+mo.getType(), moAsString); //<- Send Event to Microservice B        } catch (Exception e) {            throw new TechnicalRuntimeException(e.getMessage(), e);        }    }}

Then, the event is sent to Microservice B. The Microservice B responds with another event to the PickerManager microservice once the message processing has been completed. This message arrives in the Picker's queue.

@TxServicepublic class ListenerConfiguration {    private final AcknowledgmentHandler acknowledgmentHandler;    private final Services services;    private static final Logger LOGGER = LoggerFactory.getLogger(ListenerConfiguration.class);    @Autowired    public ListenerConfiguration(        AcknowledgmentHandler acknowledgmentHandler,        Services services    ) {        this.acknowledgmentHandler = acknowledgmentHandler;        this.services = services;    }    // The queue is triggered when a new message is received.    @RabbitListener(queues = "${corren.driver.pickers.acknowledgements.queue-name}")    public void receiveAcknowledgmentCommand(String message) throws Exception {        final Gson gson = new GsonBuilder().create();        AcknowledgementMO acknowledgementMO = gson.fromJson(message, AcknowledgementMO.class);        acknowledgmentHandler.handler(acknowledgementMO);    }}

Well. Now, I let's save a Picker inside DB. For doing that I'm using the following method inside Picker class

@Componentclass Picker {    @Autowired    public Picker(Services services,                  ApplicationEventPublisher eventPublisher,                  UtilsPickerManager utilsPickerManager,                  UtilsAW utilsAW) throws Exception {        this.services = services;        this.eventPublisher = eventPublisher;    }    public void savePicker() {      PickerEO picker = new PickerEO();      services.getPickerManager().save(pickerEO);    }}

Alright. Now, I'm checking if Picker exist in DB from the services contained inside the Picker class. And, yes ! It well exist. Great.enter image description here

What is really really weired now. I want to check from the class ListenerConfiguration through the service attribute (which is @Autowired also) if the Picker exist in DB. And... Guess what. No! The picker value is not inside the results.

enter image description here

We are agree to say that is not normal at all because the both service inside the both class have been injected by using the @Autowired decorator. So it's should be the same instance of the object. Of course I've check that. Inside the both class, the service attribute have the same ID value. So it confirm that it's the same object.

Screen of the service ID from Picker classenter image description here

Screen of the service ID from ListenerConfiguration classenter image description here

I'm blocked at that point.

If someone have an idea. Thank you for your time.


Viewing all articles
Browse latest Browse all 54

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>