nerdexam
Oracle

1Z0-895 · Question #51

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

The correct answer is A. You use a connection factory to create a session. 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…

JMS and Message-Driven Beans

Question

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

Options

  • AYou use a connection factory to create a session.
  • BWhen you create a session, you specify whether or not it is transacted.
  • CWhen you create a connection, you specify the acknowledgment mode.
  • DWhen you create a message producer, you must specify the name of the destination to which you will send

How the community answered

(36 responses)
  • A
    75% (27)
  • B
    8% (3)
  • C
    14% (5)
  • D
    3% (1)

Explanation

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);

Topics

#JMS session creation#connection factory#transacted session#acknowledgment mode

Community Discussion

No community discussion yet for this question.

Full 1Z0-895 Practice