Which statement is true?

You are writing a client that sends a message to a JMS queue. Which statement is true?

You are writing a client that sends a message to a JMS queue. Which statement is true?

A.
You use a connection factory to create a session.

B.
When you create a session, you specify whether or not it is transacted.

C.
When you create a connection, you specify the acknowledgment mode.

D.
When you create a message producer, you must specify the name of the destination to which
you will send messages.

Explanation:
Note:
The SimpleMessageClient sends messages to the queue that the SimpleMessageBean listens to.
The client starts by injecting the connection factory and queue resources:
@Resource(mappedName=”jms/ConnectionFactory”)
private static ConnectionFactory connectionFactory;
@Resource(mappedName=”jms/Queue”)
private static Queue queue;
Next, the client creates the connection, session, and message producer:
connection = connectionFactory.createConnection();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
messageProducer = session.createProducer(queue);
Finally, the client sends several messages to the queue:
message = session.createTextMessage();
for (int i = 0; i < NUM_MSGS; i++) {
message.setText(“This is message ” + (i + 1));
System.out.println(“Sending message: ” + message.getText());
messageProducer.send(message);
}



Leave a Reply 6

Your email address will not be published. Required fields are marked *


Angel Bañuelos

Angel Bañuelos

B

Angel Bañuelos

Angel Bañuelos

It’s not D, because you can specify the Destination at the time of sending the message.

It’s not A, Because you use the Connetion Factory to create the conection. Then you create the connection you can create the session.

Figaro

Figaro

B.
The methods used to create session are:
1. createSession(boolean transacted, int acknowledgeMode),
2. createQueueSession(boolean transacted, int acknowledgeMode)
3. createTopicSession(boolean transacted, int acknowledgeMode)