Question
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MapMessage;
import javax.jms.MessageProducer;
import javax.jms.Session;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.command.ActiveMQQueue;
public class FrontDeskImpl implements FrontDesk {
public void sendMail(Mail mail) {
ConnectionFactory cf =
new ActiveMQConnectionFactory("tcp://localhost:61616");
Destination destination = new ActiveMQQueue("mail.queue");
Connection conn = null;
try {
conn = cf.createConnection();
Session session =
conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(destination);
MapMessage message = session.createMapMessage();
message.setString("mailId", mail.getMailId());
message.setString("country", mail.getCountry());
message.setDouble("weight", mail.getWeight());
producer.send(message);
session.close();
} catch (JMSException e) {
throw new RuntimeException(e);
} finally {
if (conn != null) {
try {
conn.close();
} catch (JMSException e) {
}
}
}
}
}
a.
topic
b.
queue
c.
all of the mentioned
d.
none of the mentioned
Posted under Java Spring Framework
Engage with the Community - Add Your Comment
Confused About the Answer? Ask for Details Here.
Know the Explanation? Add it Here.
Q. In JMS, there are two types of destinations:-
Similar Questions
Discover Related MCQs
Q. There are several types of messages defined in the JMS API, including:-
View solution
Q. To send a JMS message with this template, you simply call:-
View solution
Q. The MessageCreator interface declares method:-
View solution
Q. A JMS template helps you to obtain and release the JMS connection and session.
View solution
Q. JMS sender and receiver classes can also extend to retrieve a JMS template:-
View solution
Q. When you need access to the JMS template.
View solution
Q. Spring provides an implementation of SimpleMessageConvertor to handle the translation of a JMS message received.
View solution
Q. By default, the JMS template uses SimpleMessageConverter for converting TextMessage to or from a string.
View solution
Q. For your front desk and back office classes, you can send and receive a map using the:-
View solution
Q. When you call the receive() method on a JMS message consumer to receive a message.
View solution
Q. EJB component which was introduced for asynchronous reception of JMS messages.
View solution
Q. MDB must implements interfaces:-
View solution
Q. In EJB 3.0, an MDB can be a POJO that implements the MessageListener interface and is annotated with the:-
View solution
Q. You create a message listener to listen for JMS messages. This negates the need for the approach taken in BackOfficeImpl in previous recipes.
View solution
Q. A message listener must implement the:-
View solution
Q. When a JMS message arrives, the onMessage() method will be called with the message as the method argument.
View solution
Q. Method to convert MapMessage Object into Spring runtime exception JmsException.
View solution
Q. Spring provides several types of message listener containers:-
View solution
Q. If you have a transaction requirement in receiving messages, you have to use:-
View solution
Q. You have to set the delegate property of MessageListenerAdapter to your target bean.
View solution
Suggested Topics
Are you eager to expand your knowledge beyond Java Spring Framework? We've curated a selection of related categories that you might find intriguing.
Click on the categories below to discover a wealth of MCQs and enrich your understanding of Computer Science. Happy exploring!