Skip to content

Commit

Permalink
v0.5.0 replyTo fix
Browse files Browse the repository at this point in the history
  • Loading branch information
antonwierenga committed Jan 24, 2018
1 parent 03a5937 commit 94d5d1f
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ organization := "com.antonwierenga"

name := "activemq-cli"

version := "0.4.0"
version := "0.5.0"

scalaVersion := "2.11.6"

Expand Down
5 changes: 4 additions & 1 deletion src/main/scala/activemq/cli/ActiveMQCLI.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ class ActiveMQCLI extends CommandMarker {

object ActiveMQCLI extends App {

lazy val ReleaseNotes = Map("v0.4.0" List(
lazy val ReleaseNotes = Map("v0.5.0" List(
"Updated shell command 'send-message': new option --reply-to",
"Fixed a bug that caused the <reply-to> header to be omitted when sending messages from file"
), "v0.4.0" List(
"Updated shell command 'connect': option --broker now uses tab completion",
"Updated shell command 'list-messages': option --queue now mandatory",
"Fixed a bug that prevented the embedded broker from being started",
Expand Down
8 changes: 5 additions & 3 deletions src/main/scala/activemq/cli/command/MessageCommands.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class MessageCommands extends Commands {
val JMSCorrelationID = ("JMSCorrelationID", "correlation-id")
val JMSPriority = ("JMSPriority", "priority")
val JMSDeliveryMode = ("JMSDeliveryMode", "delivery-mode")
val JMSReplyTo = ("JMSReplyTo", "reply-to")
val TimeToLive = ("timeToLive", "time-to-live")

@CliAvailabilityIndicator(Array("move-messages", "copy-messages", "list-messages", "send-message", "export-messages"))
Expand Down Expand Up @@ -86,6 +87,7 @@ class MessageCommands extends Commands {
@CliOption(key = Array("topic"), mandatory = false, help = "The name of the topic") topic: String,
@CliOption(key = Array("body"), mandatory = false, help = "The body of the message") body: String,
@CliOption(key = Array("correlation-id"), mandatory = false, help = "The correlation id of the message") correlationId: String,
@CliOption(key = Array("reply-to"), mandatory = false, help = "Name of the destination (topic or queue) the message replies should be sent to") replyTo: String,
@CliOption(key = Array("delivery-mode"), mandatory = false, help = "The delivery mode of the message") deliveryMode: DeliveryMode,
@CliOption(key = Array("time-to-live"), mandatory = false, help = "The time to live (in milliseconds) of the message") timeToLive: String,
@CliOption(key = Array("priority"), mandatory = false, help = "The priority of the message") priority: String,
Expand All @@ -105,7 +107,7 @@ class MessageCommands extends Commands {
s"Error in $file line: ${spe.getLineNumber}, column: ${spe.getColumnNumber}, error: ${spe.getMessage}"
)
}
if (correlationId || Option(deliveryMode).isDefined || timeToLive || priority || timeToLive) {
if (replyTo || correlationId || Option(deliveryMode).isDefined || timeToLive || priority || timeToLive) {
throw new IllegalArgumentException("When --file is specified only --queue or --topic is allowed")
}
}
Expand All @@ -124,7 +126,7 @@ class MessageCommands extends Commands {
if (body) {
val headers = new java.util.HashMap[String, String]()
for (
(key, value) Map(JMSCorrelationID correlationId, JMSPriority priority, TimeToLive timeToLive,
(key, value) Map(JMSReplyTo replyTo, JMSCorrelationID correlationId, JMSPriority priority, TimeToLive timeToLive,
JMSDeliveryMode Option(deliveryMode).getOrElse(DeliveryMode.PERSISTENT).getJMSDeliveryMode)
) {
if (Option(value).isDefined) headers.put(key._1, value.toString)
Expand All @@ -137,7 +139,7 @@ class MessageCommands extends Commands {
for (i (1 to times)) yield {
(XML.loadFile(file) \ "jms-message").map(xmlMessage {
val headers = new java.util.HashMap[String, String]()
Seq(JMSCorrelationID, JMSPriority, TimeToLive, JMSDeliveryMode).map(header {
Seq(JMSCorrelationID, JMSPriority, TimeToLive, JMSDeliveryMode, JMSReplyTo).map(header {
if (!(xmlMessage \ "header" \ header._2).isEmpty) headers.put(header._1, (xmlMessage \ "header" \ header._2).text)
})
if (!headers.containsKey(JMSDeliveryMode._1)) headers.put(JMSDeliveryMode._1, DeliveryMode.PERSISTENT.getJMSDeliveryMode.toString)
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/activemq/cli/plugin/BannerProvider.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class BannerProvider extends DefaultBannerProvider {
| """.stripMargin
}

override def getVersion: String = ActiveMQCLI.ReleaseNotes.keysIterator.next
override def getVersion: String = ActiveMQCLI.ReleaseNotes.keySet.toSeq.sorted.reverse.head

override def getWelcomeMessage: String = s"Welcome to ActiveMQ CLI $getVersion"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class MessageCommandsTests {

@Test
def testSendAndExportInlineMessageAllHeadersProvided = {
assertEquals(info("Messages sent to queue 'testQueue': 1"), shell.executeCommand("send-message --queue testQueue --correlation-id testCorrelationId --delivery-mode NON_PERSISTENT --time-to-live 2000 --priority 1 --body testMessage").getResult)
assertEquals(info("Messages sent to queue 'testQueue': 1"), shell.executeCommand("send-message --queue testQueue --reply-to replyQueue --correlation-id testCorrelationId --delivery-mode NON_PERSISTENT --time-to-live 2000 --priority 1 --body testMessage").getResult)
assertEquals(info("Messages listed: 1"), shell.executeCommand("list-messages --queue testQueue").getResult)

val messageFilePath = createTempFilePath("MessageCommandsTests_testSendAndExportMessage")
Expand All @@ -93,7 +93,7 @@ class MessageCommandsTests {
assertFalse((xml \ "jms-message" \ "header" \ "destination").isEmpty)
assertEquals("1", (xml \ "jms-message" \ "header" \ "priority") text)
assertEquals("false", (xml \ "jms-message" \ "header" \ "redelivered") text)
assertTrue((xml \ "jms-message" \ "header" \ "reply-to").isEmpty)
assertEquals("queue://replyQueue", (xml \ "jms-message" \ "header" \ "reply-to") text)
assertFalse((xml \ "jms-message" \ "header" \ "timestamp").isEmpty)
assertTrue((xml \ "jms-message" \ "header" \ "type").isEmpty)
assertEquals("testMessage", (xml \ "jms-message" \ "body") text)
Expand Down

0 comments on commit 94d5d1f

Please sign in to comment.