Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package airport.services.dispatcher; import airport.database.dispatcher.airplane.Flight; import javax.jms.Session; import javax.jms.Topic; import javax.naming.InitialContext; import javax.naming.NamingException; import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jms.core.JmsTemplate; import org.springframework.stereotype.Component; /** * * @author mcdoker */ @Component public class GeneratorFlightJMS { private static final Logger LOG = Logger.getLogger(GeneratorFlightJMS.class); @Autowired private JmsTemplate jmsTemplate; private Topic topic; public GeneratorFlightJMS() { try { this.topic = (Topic) new InitialContext().lookup("jms/FlightTopic"); } catch (NamingException ex) { } } public void sendFlight(Flight flight) { jmsTemplate.send(topic, (Session sn) -> sn.createObjectMessage(flight)); if (LOG.isInfoEnabled()) { LOG.info("send message. Flight : " + flight); } } }