package com.epam.cdp.jee.todo.jms.listener;

import lombok.extern.slf4j.Slf4j;

import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.Message;
import javax.jms.MessageListener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@MessageDriven(name = "TaskQueueMDB", activationConfig = {
        @ActivationConfigProperty(propertyName = "destinationType",
                propertyValue = "javax.jms.Queue"),
        @ActivationConfigProperty(propertyName = "destination",
                propertyValue = "java:jboss/exported/jms/queue/task") })
@Slf4j
public class TaskMessageListener implements MessageListener {

    @Override
    public void onMessage(final Message message) {
        log.info("Message was received: '{}'", message);
    }
}

@@ -73,16 +73,39 @@
 Slf4j;%0A%0A
+import java.util.Date;%0A
 import j
@@ -188,107 +188,339 @@
 vax.
-jms.Message;%0Aimport javax.jms.MessageListener;%0A%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFac
+inject.Inject;%0Aimport javax.jms.JMSException;%0Aimport javax.jms.Message;%0Aimport javax.jms.MessageListener;%0Aimport javax.jms.TextMessage;%0A%0Aimport org.joda.time.DateTime;%0A%0Aimport com.epam.cdp.jee.todo.persistence.Jpa;%0Aimport com.epam.cdp.jee.todo.persistence.entity.Task;%0Aimport com.epam.cdp.jee.todo.persistence.repository.TaskReposi
 tory
@@ -834,17 +834,16 @@
 e/task%22)
- 
 %7D)%0A@Slf4
@@ -907,16 +907,81 @@
 ener %7B%0A%0A
+    @Inject%0A    @Jpa%0A    private TaskRepository taskRepository;%0A%0A
     @Ove
@@ -1049,56 +1049,347 @@
     
-log.info(%22Message was received: '%7B%7D'%22, message);
+TextMessage textMessage = (TextMessage) message;%0A        try %7B%0A            String taskName = textMessage.getText();%0A            Task task = new Task(new Date().getTime(), taskName, new DateTime());%0A            taskRepository.add(task);%0A        %7D catch (JMSException e) %7B%0A            log.error(%22Unable to process JMS message%22, e);%0A        %7D
 %0A   

Add task creation through JMS