public class Async extends Object
EmbeddedJMS to
sensible values so you do not have to.
This class also implements a Command Pattern for ease of writing asynchronous code.| Constructor and Description |
|---|
Async(String dataDirectory,
boolean useLibAio,
com.google.inject.Injector injector,
QueueConfig... queueConfigs)
Creates and configures a new instance.
|
Async(String dataDirectory,
boolean useLibAio,
QueueConfig... queueConfigs)
Creates and configures a new instance.
|
| Modifier and Type | Method and Description |
|---|---|
void |
configureNetty(String host,
int port)
Call this method once after a constructor in order to create a Netty instance to accept out of VM messages.
|
BatchReceiver |
getBatchReceiver(String queueName,
long timeout)
Generate a
BatchReceiver to receive and process stored messages. |
static byte[] |
getBytes(javax.jms.BytesMessage message) |
org.apache.activemq.artemis.core.config.Configuration |
getConfig()
Get additional server configuration.
|
org.apache.activemq.artemis.jms.server.config.JMSConfiguration |
getJmsConfig()
Get additional JMS configuration.
|
long |
getMessageCount(String queue)
Returns number of messages currently in queue
|
Map<String,Long> |
getMessageCounts()
Returns counts of messages for all queues.
|
List<Command> |
getTopCommands(int count,
String queueName)
Returns top commands in queue.
|
List<String> |
getTopTextMessages(int maxSize,
String queueName)
Returns top
TextMessages in queue. |
boolean |
isPaused(String queueName) |
protected javax.jms.Message |
lookupMessage(String queueName)
This method exists for testing
|
boolean |
moveMessage(String jmsMessageId,
String source,
String target)
Moves a message from one queue to another
|
int |
moveMessages(String source,
String target)
Moves all messages from one queue to another
|
void |
pause(String queueName)
Pauses a queue.
|
Command |
receiveCommand(String queueName)
Receives a command from a queue synchronously.
|
<T extends Command> |
receiveCommand(String queueName,
Class<T> type)
Receives a command from a queue synchronously.
|
<T extends Command> |
receiveCommand(String queueName,
int timeout,
Class<T> type)
Receives a command from a queue synchronously.
|
Command |
receiveCommand(String queueName,
long timeout)
Receives a command from a queue synchronously.
|
javax.jms.Message |
receiveMessage(String queueName,
long timeout)
Receives a messafge from a queue asynchronously.If this queue also has listeners, then messages will be distributed across
all consumers.
|
int |
removeAllMessages(String queueName)
Removes all messages from queue.
|
int |
removeMessages(String queueName,
String filter)
Removes messages from queue.
|
void |
resume(String queueName)
Resumes a paused queue
|
void |
send(String queueName,
Command command)
Sends a command into a queue for processing
|
void |
send(String queueName,
Command command,
int deliveryMode)
Sends a command into a queue for processing
|
void |
send(String queueName,
Command command,
int deliveryMode,
int priority,
int timeToLive)
Sends a command into a queue for processing
|
void |
sendTextMessage(String queueName,
String text)
Sends a non-expiring
TextMessage with average priority. |
void |
sendTextMessage(String queueName,
String text,
int deliveryMode,
int priority,
int timeToLive)
Sends a
TextMessage. |
void |
setBinaryMode(boolean binaryMode)
If true, uses binary mode to send messages.
|
void |
start()
Starts the server.
|
void |
stop()
Stops this JMS server.
|
public Async(String dataDirectory, boolean useLibAio, QueueConfig... queueConfigs)
dataDirectory - root directory where persistent messages are storeduseLibAio - true to use libaio, false not to use (See Artemis log statements to check if it was detected).queueConfigs - vararg of QueueConfig instances.public Async(String dataDirectory, boolean useLibAio, com.google.inject.Injector injector, QueueConfig... queueConfigs)
dataDirectory - root directory where persistent messages are storeduseLibAio - true to use libaio, false to use NIO.injector - Google Guice injector. Used to inject dependency members into commands if needed.queueConfigs - vararg of QueueConfig> instances.public void start()
public void stop()
public void setBinaryMode(boolean binaryMode)
binaryMode - true to send messages in binary mode, false to send as strings.public void configureNetty(String host, int port)
host - host to bind toport - port to listen onpublic void send(String queueName, Command command)
queueName - name of queuecommand - command instance.public void send(String queueName, Command command, int deliveryMode)
queueName - name of queuecommand - command to processdeliveryMode - delivery mode: DeliveryMode.public void send(String queueName, Command command, int deliveryMode, int priority, int timeToLive)
queueName - name of queuecommand - command to processdeliveryMode - delivery mode: DeliveryMode.priority - priority of the message. Correct values are from 0 to 9, with higher number denoting a
higher priority.timeToLive - the message's lifetime (in milliseconds, where 0 is to never expire)public Command receiveCommand(String queueName)
queueName - name of queue#receiveCommand(String, long)}public <T extends Command> T receiveCommand(String queueName, Class<T> type)
queueName - name of queuetype - expected class of a command#receiveCommand(String, long)}public <T extends Command> T receiveCommand(String queueName, int timeout, Class<T> type)
queueName - name of queuetimeout - timeout in milliseconds. If a command is not received during a timeout, this methods returns null.type - expected class of a command#receiveCommand(String, long)}public Command receiveCommand(String queueName, long timeout)
queueName - name of queuetimeout - timeout in milliseconds. If a command is not received during a timeout, this methods returns null.public javax.jms.Message receiveMessage(String queueName, long timeout)
queueName - name of queuetimeout - timeout in millis.public void sendTextMessage(String queueName, String text)
TextMessage with average priority.queueName - name of queuetext - body of messagepublic void sendTextMessage(String queueName, String text, int deliveryMode, int priority, int timeToLive)
TextMessage.queueName - name of queuetext - body of messagedeliveryMode - delivery mode: DeliveryMode.priority - priority of the message. Correct values are from 0 to 9, with higher number denoting a
higher priority.timeToLive - the message's lifetime (in milliseconds, where 0 is to never expire)public BatchReceiver getBatchReceiver(String queueName, long timeout)
BatchReceiver to receive and process stored messages.
This method ALWAYS works in the context of a transaction.queueName - name of queuetimeout - timeout to wait.BatchReceiver.public List<Command> getTopCommands(int count, String queueName)
count - number of commands to lookup.public List<String> getTopTextMessages(int maxSize, String queueName)
TextMessages in queue. Does not remove anything from queue. This method can be used for
an admin tool to peek inside the queue.maxSize - max number of messages to lookup.protected javax.jms.Message lookupMessage(String queueName)
public static byte[] getBytes(javax.jms.BytesMessage message)
throws javax.jms.JMSException
javax.jms.JMSExceptionpublic Map<String,Long> getMessageCounts()
public long getMessageCount(String queue)
queue - queue namepublic void resume(String queueName)
queueName - queue namepublic void pause(String queueName)
queueName - queue name.public boolean isPaused(String queueName)
queueName - queue namepublic int removeMessages(String queueName, String filter)
queueName - queue namefilter - filter selector as in JMS specification.
See: JMS Message Selectorspublic int removeAllMessages(String queueName)
queueName - queue name.public int moveMessages(String source, String target)
source - name of source queuetarget - name of target queuepublic boolean moveMessage(String jmsMessageId, String source, String target)
jmsMessageId - JMS message id of a message to movesource - name of source queuetarget - name of target queuepublic org.apache.activemq.artemis.jms.server.config.JMSConfiguration getJmsConfig()
public org.apache.activemq.artemis.core.config.Configuration getConfig()
Copyright © 2020 JavaLite. All rights reserved.