I have a service which updates a cell in MySQL. The service works perfectly fine when called from a controller.
But the same service fails to persist data when called from MessageListener. My listener looks something like below
public class KeySpaceNotificationMessageListener implements MessageListener
{
@Autowired
ServiceImpl service;
@Override
public void onMessage(Message message, byte[] pattern)
{
if( (data = createPublishData(new String(message.getBody()), new String(message.getChannel()))) != null)
{
LOG.info("publishing data to deepstream channel with payload = {}", data);
}
private String createPublishData(String messageBody, String messageChannel)
{
//find id from message channel
service.unAssign(id);
return someString;
}
}
ServiceImpl Unassign method
@Override
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
public ResponseEntity<String> unAssign(Long Id)
{
Optional<Image> Image = ImageRepository.findById(Id);
if(!Image.isPresent())
throw new ResourceNotFoundException("could not find image with id = " + Id);
Image.get().setAssignedTo(null);
return new ResponseEntity<String>("Unassign successfull", HttpStatus.OK);
}
Any help is appreciated.