"producer-max-rate" does work as expected in HornetQ with JAX-RS client
Issue
I am sending messages to a queue with this code:
public static boolean sendMessageToQueue(final Serializable msg,
final String queueName, final long expirationInMilliseconds) {
InitialContext context = null;
Connection connection = null;
Destination destination = null;
Session session = null;
MessageProducer messageProducer = null;
try {
// create connection to JBoss server
context = new InitialContext();
// lookup for the clustered connection factory
final ConnectionFactory connectionFactory =
(QueueConnectionFactory) context
.lookup(JAVA_CONNECTION_FACTORY);
// initialize the send page messaging
// lookup for the queue
destination =
(Destination) context.lookup(QUEUE_PREFIX + queueName);
// create connection
connection = createJMSConnection(connectionFactory);
// create session
try {
session =
connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
} catch (final JMSException e) {
closeResources(context, connection, session, messageProducer);
connection = createJMSConnection(connectionFactory);
session =
connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
}
// create producer to the queue
messageProducer = session.createProducer(destination);
// create the jms message
final ObjectMessage message = session.createObjectMessage(msg);
// final TextMessage message = session.createTextMessage(msg
// .toString());
if (expirationInMilliseconds > 0) {
message.setJMSExpiration(expirationInMilliseconds);
}
messageProducer.send(message);
return true;
} catch (final JMSException ex) {
ex.printStackTrace();
} catch (final NamingException e) {
e.printStackTrace();
} finally {
closeResources(context, connection, session, messageProducer);
}
return false;
}
private static Connection createJMSConnection(
final ConnectionFactory connectionFactory) throws JMSException {
// create connection
final Connection connection = connectionFactory.createConnection();
// start the queue connection
connection.start();
return connection;
}
private static void closeResources(final InitialContext context,
final Connection connection, final Session session,
final MessageProducer messageProducer) {
try {
if (context != null) {
context.close();
}
if (session != null) {
session.close();
}
if (messageProducer != null) {
messageProducer.close();
}
if (connection != null) {
connection.close();
}
} catch (final Exception e) {
}
}
- This is the method which uses this code:
int count = Integer.valueOf(messages);
for(int i=0;i<count;i++){
String msg = "message number " + (i+1);
JmsUtils.sendMessageToQueue(msg, "OrdersQueue");
System.out.println("message: " + msg + " sent to OrdersQueue");
}
- It works fine but if I add the "producer-max-rate" element to the pooled-connection-factory name="hornetq-ra" then I can see that the printing System.out.println("message: " + msg + " sent to OrdersQueue");
is done only every second. Why is this behaviour?
<pooled-connection-factory name="hornetq-ra">
<producer-max-rate>50</producer-max-rate>
<transaction mode="xa"></transaction>
<connectors>
<connector-ref connector-name="in-vm"></connector>
</connectors>
<entries>
<entry name="java:/JmsXA"></entry>
</entries>
</pooled-connection-factory>
- It does not matter which number I set in "producer-max-rate".
Environment
- Red Hat JBoss Enterprise Application Platform (EAP)
- 6.x
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.