class MessagePublisher implements AutoCloseable {

	synchronized void publish(Message message) throws Exception {
		LoggingService.logDebug(MODULE_NAME, "Start publish message :" + this.name );
		byte[] bytes = message.getBytes();

		try {
			archive.save(bytes, message.getTimestamp());
		} catch (Exception e) {
			logError(MODULE_NAME, "Message Publisher (" + this.name + ")unable to archive message",
					new AgentSystemException(e.getMessage(), e));
		}

		for (MessageProducer producer: producers) {
			try {
				TextMessage msg = MessageBusServer.createMessage(message.toJson().toString());
				producer.send(msg, DeliveryMode.NON_PERSISTENT, javax.jms.Message.DEFAULT_PRIORITY, javax.jms.Message.DEFAULT_TIME_TO_LIVE);
			} catch (Exception e) {
				logError(MODULE_NAME, "Message Publisher (" + this.name + ") unable to send message",
						new AgentSystemException(e.getMessage(), e));
			}
		}
		LoggingService.logDebug(MODULE_NAME, "Finished publish message : " + this.name);
	}

	public  MessagePublisher(String name, Route route, List<MessageProducer> producers);

}