class MessageReceiver implements AutoCloseable {

	synchronized List<Message> getMessages() throws Exception {
		LoggingService.logDebug(MODULE_NAME, String.format("Start getting message \"%s\"", name));
		List<Message> result = new ArrayList<>();
		
		if (consumer != null || listener == null) {
			Message message = getMessage();
			while (message != null) {
				result.add(message);
				message = getMessage();
			}
		}
		LoggingService.logDebug(MODULE_NAME, String.format("Finished getting message \"%s\"", name));
		return result;
	}

	public  MessageReceiver(String name, MessageConsumer consumer);

}