@Override
 @Transactional
 public void writeItems(List<Object> items) throws Exception {
   try (PrintWriter archive =
       new PrintWriter(
           new BufferedWriter(
               new FileWriter(
                   new File(
                       jobContext.getProperties().getProperty(ARCHIVE_DIRECTORY)
                           + "/archive_"
                           + jobContext.getJobName()
                           + "_"
                           + jobContext.getInstanceId()
                           + ".csv"),
                   true)))) {
     for (Object item : items) {
       HandlingEventRegistrationAttempt attempt = (HandlingEventRegistrationAttempt) item;
       applicationEvents.receivedHandlingEventRegistrationAttempt(attempt);
       archive.println(
           attempt.getRegistrationTime()
               + ","
               + attempt.getCompletionTime()
               + ","
               + attempt.getTrackingId()
               + ","
               + attempt.getVoyageNumber()
               + ","
               + attempt.getUnLocode()
               + ","
               + attempt.getType());
     }
   }
 }
 @Override
 public void onMessage(Message message) {
   try {
     ObjectMessage objectMessage = (ObjectMessage) message;
     HandlingEventRegistrationAttempt attempt =
         (HandlingEventRegistrationAttempt) objectMessage.getObject();
     handlingEventService.registerHandlingEvent(
         attempt.getCompletionTime(),
         attempt.getTrackingId(),
         attempt.getVoyageNumber(),
         attempt.getUnLocode(),
         attempt.getType());
   } catch (JMSException | CannotCreateHandlingEventException e) {
     // Poison messages will be placed on dead-letter queue.
     throw new RuntimeException("Error occurred processing message", e);
     //        } catch (JMSException e) {
     // logger.log(Level.SEVERE, e.getMessage(), e);
   }
 }