Skip to content

Commit

Permalink
Implement --conn-anonymous-producer option
Browse files Browse the repository at this point in the history
  • Loading branch information
jiridanek committed Mar 26, 2023
1 parent c488674 commit f3b1cf2
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ void setOptions(ClientOptionManager clientOptionManager, @Args String[] args) {
public static final String CONN_TCP_NO_DELAY = "conn-tcp-no-delay"; // wireFormat.tcpNoDelayEnabled
public static final String CONN_TIGHT_ENCODING_ENA = "conn-tight-encoding-ena"; // wireFormat.tightEncodingEnabled
public static final String CONN_WATCH_TOPIC_ADVISORIES = "conn-watch-topic-advisories";
public static final String CONN_ANONYMOUS_PRODUCER = "conn-anonymous-producer";

// TODO Not implemented by client libraries
// static final String CON_SSL_PROTOCOL = "conn-ssl-protocol";
Expand Down
10 changes: 8 additions & 2 deletions jakartalib/src/main/java/com/redhat/mqe/lib/SenderClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ public void startClient() {
Session session = (transaction == null || transaction.equals("none")) ?
this.createSession(senderOptions, connection, false) : this.createSession(senderOptions, connection, true);
connection.start();
MessageProducer msgProducer = session.createProducer(this.getDestination());

boolean anonymousProducer = Utils.convertOptionToBoolean(senderOptions.getOption(ClientOptions.CONN_ANONYMOUS_PRODUCER).getValue());
MessageProducer msgProducer = anonymousProducer ? session.createProducer(null) : session.createProducer(this.getDestination());
setMessageProducer(senderOptions, msgProducer);

// Calculate msg-rate from COUNT & DURATION
Expand All @@ -104,7 +106,11 @@ public void startClient() {

// Send messages
try {
msgProducer.send(message);
if (anonymousProducer) {
msgProducer.send(getDestination(), message);
} else {
msgProducer.send(message);
}
} catch (Exception e) {
switch (e.getCause().getClass().getName()) {
case "org.apache.qpid.jms.provider.exceptions.ProviderDeliveryReleasedException":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class SenderOptions extends ClientOptions {
new Option(PROPERTY_TYPE, "", "PTYPE", "String", "specify the type of message property"),
new Option(MSG_PROPERTY, "", "KEY=PVALUE", "", "specify message property as KEY=VALUE (use '~' instead of '=' for auto-casting)"),
new Option(CONTENT_TYPE, "", "CTYPE", "String", "specify type of the actual content type"),
new Option(CONN_ANONYMOUS_PRODUCER, "", "ANONYMOUS", "no", "create anonymous (no queue specified) producer"),
new Option(MSG_CONTENT_TYPE, "", "MSGTYPE", "", "type of JMSMessageBody to use in header"),
new Option(MSG_CONTENT_FROM_FILE, "", "PATH", "", "specify filename to load content from"),
new Option(MSG_CONTENT, "", "CONTENT", "", "actual content fed to message body"),
Expand Down
1 change: 1 addition & 0 deletions jmslib/src/main/java/com/redhat/mqe/lib/ClientOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ void setOptions(ClientOptionManager clientOptionManager, @Args String[] args) {
public static final String CONN_TCP_NO_DELAY = "conn-tcp-no-delay"; // wireFormat.tcpNoDelayEnabled
public static final String CONN_TIGHT_ENCODING_ENA = "conn-tight-encoding-ena"; // wireFormat.tightEncodingEnabled
public static final String CONN_WATCH_TOPIC_ADVISORIES = "conn-watch-topic-advisories";
public static final String CONN_ANONYMOUS_PRODUCER = "conn-anonymous-producer";

// TODO Not implemented by client libraries
// static final String CON_SSL_PROTOCOL = "conn-ssl-protocol";
Expand Down
10 changes: 8 additions & 2 deletions jmslib/src/main/java/com/redhat/mqe/lib/SenderClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ public void startClient() {
Session session = (transaction == null || transaction.equals("none")) ?
this.createSession(senderOptions, connection, false) : this.createSession(senderOptions, connection, true);
connection.start();
MessageProducer msgProducer = session.createProducer(this.getDestination());

boolean anonymousProducer = Utils.convertOptionToBoolean(senderOptions.getOption(ClientOptions.CONN_ANONYMOUS_PRODUCER).getValue());
MessageProducer msgProducer = anonymousProducer ? session.createProducer(null) : session.createProducer(this.getDestination());
setMessageProducer(senderOptions, msgProducer);

// Calculate msg-rate from COUNT & DURATION
Expand All @@ -104,7 +106,11 @@ public void startClient() {

// Send messages
try {
msgProducer.send(message);
if (anonymousProducer) {
msgProducer.send(getDestination(), message);
} else {
msgProducer.send(message);
}
} catch (Exception e) {
switch (e.getCause().getClass().getName()) {
case "org.apache.qpid.jms.provider.exceptions.ProviderDeliveryReleasedException":
Expand Down
1 change: 1 addition & 0 deletions jmslib/src/main/java/com/redhat/mqe/lib/SenderOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class SenderOptions extends ClientOptions {
new Option(PROPERTY_TYPE, "", "PTYPE", "String", "specify the type of message property"),
new Option(MSG_PROPERTY, "", "KEY=PVALUE", "", "specify message property as KEY=VALUE (use '~' instead of '=' for auto-casting)"),
new Option(CONTENT_TYPE, "", "CTYPE", "String", "specify type of the actual content type"),
new Option(CONN_ANONYMOUS_PRODUCER, "", "ANONYMOUS", "no", "create anonymous (no queue specified) producer"),
new Option(MSG_CONTENT_TYPE, "", "MSGTYPE", "", "type of JMSMessageBody to use in header"),
new Option(MSG_CONTENT_FROM_FILE, "", "PATH", "", "specify filename to load content from"),
new Option(MSG_CONTENT, "", "CONTENT", "", "actual content fed to message body"),
Expand Down
5 changes: 5 additions & 0 deletions lib/src/main/java/com/redhat/mqe/lib/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -294,4 +294,9 @@ public static Object getObjectValue(Class<?> clazz, String object, boolean allow
return myObj;
}


public static boolean convertOptionToBoolean(String optionStringValue) {
String optionValue = optionStringValue.toLowerCase();
return (optionValue.equals("true") || optionValue.equals("yes"));
}
}

0 comments on commit f3b1cf2

Please sign in to comment.