6 Replies Latest reply on Feb 17, 2015 2:33 PM by jdonofrio

    Not a HornetQ Destination:HornetQQueue While injecting JMS Queue with CDI

    jdonofrio Newbie

      I'm hoping that I'm just doing something silly and failing to see my error while looking at other exmaples.

       

      I'm seeing the following stack trace while using CDI producers to inject JMS resources into my application:

       

      ...

      Caused by: javax.jms.InvalidDestinationRuntimeException: Not a HornetQ Destination:HornetQQueue[metricQueue]

              at org.hornetq.jms.client.JmsExceptionUtils.convertToRuntimeException(JmsExceptionUtils.java:68)

              at org.hornetq.jms.client.HornetQJMSProducer.send(HornetQJMSProducer.java:112)

              at org.hornetq.jms.client.HornetQJMSProducer.send(HornetQJMSProducer.java:135)

              at jad.ets.metrics.ws.rest.resources.RootResource.insertMetric(RootResource.java:124) [classes:]

              ... 41 more

      Caused by: javax.jms.InvalidDestinationException: Not a HornetQ Destination:HornetQQueue[metricQueue]

              at org.hornetq.jms.client.HornetQMessageProducer.checkDestination(HornetQMessageProducer.java:333)

              at org.hornetq.jms.client.HornetQMessageProducer.send(HornetQMessageProducer.java:208)

              at org.hornetq.jms.client.HornetQMessageProducer.send(HornetQMessageProducer.java:200)

              at org.hornetq.ra.HornetQRAMessageProducer.send(HornetQRAMessageProducer.java:145)

              at org.hornetq.jms.client.HornetQJMSProducer.send(HornetQJMSProducer.java:107)

              ... 43 more

      I truncated the stack trace a little bit.

       

      The producer code looks like this:

       

      import java.util.logging.Logger;
      
      
      import javax.annotation.Resource;
      import javax.enterprise.inject.Disposes;
      import javax.enterprise.inject.Produces;
      import javax.jms.JMSException;
      import javax.jms.Queue;
      import javax.jms.QueueConnection;
      import javax.jms.QueueConnectionFactory;
      import javax.jms.QueueSession;
      import javax.jms.Session;
      
      
      public class WSResources {
        private static final Logger l = Logger.getLogger(WSResources.class.getName());
        @Resource(lookup="java:/jms/metricQueueConnectionFactory")
        private QueueConnectionFactory eventMessageQueueConnectionFactory;
      
      
        @Produces
        @Metric
        @Resource(lookup="java:/jms/metricQueue")
        private Queue eventMessageQueue;
      
        @Produces
        @Metric
        public QueueConnection createMetricQueueConnection() throws JMSException{
        l.info("Creating metric queue connection");
        return eventMessageQueueConnectionFactory.createQueueConnection();
        }
      
        @Produces
        @Metric
        public QueueSession createOrderSession(QueueConnection connection) throws JMSException{
        l.info("Creating metric queue session");
        return connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        }
      
        public void closeMetricsQueueConnection(@Disposes @Metric QueueConnection connection) throws JMSException{
        l.info("Closing metric queue connection");
        connection.close();
        }
      
        public void closeMetricsQueueSession(@Disposes @Metric QueueSession session) throws JMSException{
        l.info("Closing metric queue session");
        session.close();
        }
      }
      
      

       

      and then my code injects and uses it like this:

       

      @Path("/")
      @RequestScoped
      public class RootResource {
        private static final Logger l = Logger.getLogger(RootResource.class.getName());
        private static final DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
        @Context
        private UriInfo info;
        @Inject
        private ProjectDAO projectDAO;
        @Inject
        @Metric
        private QueueSession session;
        @Inject
        @Metric
        private Queue metricQueue;
        @Inject
        private JMSContext context;
      
        @POST
        public Response insertMetric(@QueryParam("project") String project,
        @QueryParam("metric") String metric,
        @QueryParam("timestamp") String rawTimestamp){
        // Check Request
        l.info("Request received " + info.toString());
        if(project == null || metric == null || rawTimestamp == null){
        l.info("Request missing project, metric, or timestamp parameter");
        throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity("Required parameters are project, metric, and timestamp").build());
        }
        try{
        // Check Project
        Project p = new Project();
        p.setName(project);
        Project persistedProject = projectDAO.find(p);
        if(persistedProject == null){
        StringBuilder sb = new StringBuilder()
        .append("No project with name ")
        .append(project)
        .append(" found, creating new one");
        l.info(sb.toString());
        projectDAO.insert(p);
        persistedProject = projectDAO.find(p);
        }
      
        // Create metric if not there already
        if (persistedProject.get(Project.METRIC_ATTR) == null){
        l.info("Key metrics is missing");
        projectDAO.addMetric(project, metric);
        }
        else{
        boolean flag = persistedProject.hasMetric(metric);
        if(!flag){
        projectDAO.addMetric(project, metric);
        }
        }
      
        // Insert new metric value
        MultivaluedMap<String, String> keys = info.getQueryParameters();
        Map<String, Object> valueMap = new HashMap<>();
        Date datetime = df.parse(rawTimestamp);
        for(String key : keys.keySet()){
        // Skip the expected values
        if("project".equals(key) || "metric".equals(key) || "timestamp".equals(key)){
        continue;
        }
        valueMap.put(key, keys.get(key));
        }
        projectDAO.addValueToMetric(project, metric, datetime, valueMap);
      
        // Test JMS
        l.info(metricQueue.getClass().getName());
        Destination d = metricQueue;
        context.createProducer().send(d, "This is a test text message"); // This line of code throws the exception
      
      
      // MessageProducer producer = session.createProducer(metricQueue);
      // Message msg = session.createTextMessage("This is a test text message");
      // producer.send(msg);
      
        return Response.status(Status.OK).build();
        } catch(Exception e){
        throw new WebApplicationException(e);
        }
        }
      }
      
      

       

      I have stared at this for a while and unsure why the injected queue is not cooperating.

       

      How can I fix this?