@Override public Future<Message> sendMessageAsync(final Message message) { return EXECUTOR_SERVICE.submit( () -> { String messageInvalid = messageValidator.validate(message); if (messageInvalid != null) { logger.info("### Couldn't forward Message .. -> {" + messageInvalid + "}"); return null; } else { try { Channel rabbitMqChannel = USER_CHANNEL.get(message.getToUser()); Map<String, Object> headers = new HashMap<>(); headers.put(ARGUMENT_TO_ID, message.getToUser().getId()); AMQP.BasicProperties basicProperties = new AMQP.BasicProperties.Builder().headers(headers).build(); rabbitMqChannel.basicPublish( amqpExchange, "", basicProperties, gson.toJson(message).getBytes("UTF-8")); return message; } catch (Exception ex) { logger.info("### Couldn't forward Message .. -> {" + ex.getMessage() + "}"); return null; } } }); }
public boolean notifyUser(Message message) { try { toClient.println(gson.toJson(message)); return true; } catch (Exception ex) { logger.debug( "$$$Couldn't send message to user [" + message.getToUser().getUsername() + "] due to [" + ex.getMessage() + "]"); return false; } }