Skip to content

Commit

Permalink
support JMS Priority
Browse files Browse the repository at this point in the history
  • Loading branch information
northlander committed Oct 4, 2014
1 parent 1e5a4af commit 5d39918
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
6 changes: 0 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,6 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-asm</artifactId>
<version>${spring.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
Expand Down
15 changes: 14 additions & 1 deletion src/main/java/com/libzter/a/A.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public void output(Object... args) {
public static String CMD_USER = "U";
public static String CMD_PASS = "P";
public static String CMD_SET_HEADER = "H";
public static String CMD_PRIORITY = "i";

public static String DEFAULT_COUNT_GET = "1";
public static String DEFAULT_COUNT_ALL = "0";
Expand Down Expand Up @@ -109,6 +110,7 @@ public void run(String[] args) throws InterruptedException{
opts.addOption(CMD_WAIT,"wait",true,"Time to wait on get operation. Default 50. 0 equals infinity");
opts.addOption(CMD_USER,"user",true,"Username to connect to broker");
opts.addOption(CMD_PASS,"pass",true,"Password to connect to broker");
opts.addOption(CMD_PRIORITY,"priority",true,"sets JMSPriority");
@SuppressWarnings("static-access")
Option property = OptionBuilder.withArgName("property=value" )
.hasArgs(2)
Expand Down Expand Up @@ -277,6 +279,7 @@ protected void executePut(CommandLine cmdLine) throws IOException, JMSException
Properties props = cmdLine.getOptionProperties(CMD_SET_HEADER);
String type = cmdLine.getOptionValue(CMD_TYPE,DEFAULT_TYPE);
String encoding = cmdLine.getOptionValue(CMD_ENCODING, Charset.defaultCharset().name());

Message outMsg = null;
// figure out input data
String data = cmdLine.getOptionValue(CMD_PUT);
Expand All @@ -295,7 +298,7 @@ protected void executePut(CommandLine cmdLine) throws IOException, JMSException
TextMessage textMsg = sess.createTextMessage(data);
outMsg = textMsg;
}

MessageProducer mp = sess.createProducer(createDestination(cmdLine.getArgs()[0]));
if( cmdLine.hasOption("n")){;
mp.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
Expand All @@ -309,6 +312,16 @@ protected void executePut(CommandLine cmdLine) throws IOException, JMSException
if( cmdLine.hasOption("r")){
outMsg.setJMSReplyTo(createDestination(cmdLine.getOptionValue("r")));
}

if( cmdLine.hasOption(CMD_PRIORITY)){
try{
int priority = Integer.parseInt(cmdLine.getOptionValue(CMD_PRIORITY));
mp.setPriority(priority);
}catch(NumberFormatException nfe){
throw new NumberFormatException("JMSPriority has to be an integer value");
}
}

// send multiple messages?
if( cmdLine.hasOption("c")){
int count = Integer.parseInt(cmdLine.getOptionValue("c"));
Expand Down
13 changes: 13 additions & 0 deletions src/test/java/com/libzter/a/ATestCases.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static com.libzter.a.A.CMD_GET;
import static com.libzter.a.A.CMD_PUT;
import static com.libzter.a.A.CMD_WAIT;
import static com.libzter.a.A.CMD_PRIORITY;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

Expand Down Expand Up @@ -113,6 +114,18 @@ public void testPutQueue() throws Exception{
assertEquals("test",msg.getText());
}

@Test
public void testPutWithPriority() throws Exception{
final int priority = 6;
String cmdLine = CMD_LINE_COMMON + "-" + CMD_PRIORITY +" " + priority + " -" + CMD_PUT + "\"test\""
+ " TEST.QUEUE";
a.run(cmdLine.split(" "));
MessageConsumer mc = session.createConsumer(testQueue);
TextMessage msg = (TextMessage)mc.receive(TEST_TIMEOUT);
assertEquals("test",msg.getText());
assertEquals(priority,msg.getJMSPriority());
}

@Test
public void testPutTopic() throws Exception{
String cmdLine = CMD_LINE_COMMON + "-" + CMD_PUT + "\"test\"" + " topic://TEST.TOPIC";
Expand Down

0 comments on commit 5d39918

Please sign in to comment.