[
https://issues.apache.org/jira/browse/ARTEMIS-4792?focusedWorklogId=921932&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-921932
]
ASF GitHub Bot logged work on ARTEMIS-4792:
-------------------------------------------
Author: ASF GitHub Bot
Created on: 04/Jun/24 09:36
Start Date: 04/Jun/24 09:36
Worklog Time Spent: 10m
Work Description: gemmellr commented on code in PR #4956:
URL: https://github.com/apache/activemq-artemis/pull/4956#discussion_r1625678167
##########
artemis-commons/src/main/java/org/apache/activemq/artemis/api/core/ParameterisedAddress.java:
##########
@@ -106,4 +107,46 @@ public static boolean isParameterised(SimpleString
address) {
return URISupport.containsQuery(address);
}
+ public static SimpleString extractAddress(SimpleString address) {
+ return SimpleString.toSimpleString(extractAddress(address.toString()));
+ }
+
+ /**
+ * Given an address string, extract only the query portion if the address is
+ * parameterized, otherwise return an empty {@link Map}.
+ *
+ * @param address
+ * The address to operate on.
+ *
+ * @return a {@link Map} containing the parameters associated with the
given address.
+ */
+ @SuppressWarnings("unchecked")
+ public static Map<String, String> extractParameters(String address) {
+ final int index = address.indexOf('?');
+
+ if (index == -1) {
+ return Collections.EMPTY_MAP;
+ } else {
+ return parseQuery(address);
+ }
+ }
+
+ /**
+ * Given an address string, extract only the address portion if the address
is
+ * parameterized, otherwise just return the provided address.
+ *
+ * @param address
+ * The address to operate on.
+ *
+ * @return the original address minus any appended parameters.
+ */
+ public static String extractAddress(String address) {
+ final int index = address.indexOf('?');
+
+ if (index == -1) {
+ return address;
+ } else {
+ return address.substring(0, index);
+ }
+ }
Review Comment:
The methods cant handle a null but dont say that and the 'otherwise return
provided' bit might imply otherwise. Should either say so or handle it.
##########
artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/DefaultSenderController.java:
##########
@@ -409,16 +419,38 @@ public Consumer init(ProtonServerSenderContext
senderContext) throws Exception {
// have not honored what it asked for.
source.setFilter(supportedFilters.isEmpty() ? null : supportedFilters);
- boolean browseOnly = !multicast && source.getDistributionMode() != null
&& source.getDistributionMode().equals(COPY);
+ final boolean browseOnly = !multicast && source.getDistributionMode() !=
null && source.getDistributionMode().equals(COPY);
+ final Number consumerPriority =
getReceiverPriority(protonSender.getRemoteProperties(),
extractConsumerPriority(addressParameters));
+
+ // Any new parameters used should be extracted from the values parsed
from the address to avoid this log message.
+ if (!addressParameters.isEmpty()) {
+ final String unusedParametersMessage = ""
+ + " Not all specified address options were applicable to the
created server consumer."
+ + " Check the options are spelled correctly."
+ + " Unused parameters=[" + addressParameters + "].";
+
+ logger.debug(unusedParametersMessage);
+ }
+
+ return sessionSPI.createSender(senderContext, queue, multicast ? null :
selector, browseOnly, consumerPriority);
+ }
+
+ private static Number extractConsumerPriority(Map<String, String>
addressParameters) {
+ if (addressParameters != null && !addressParameters.isEmpty() ) {
+ final String priorityString =
addressParameters.remove(QueueConfiguration.CONSUMER_PRIORITY);
+ if (priorityString != null) {
+ return Integer.valueOf(priorityString);
+ }
+ }
- return (Consumer) sessionSPI.createSender(senderContext, queue,
multicast ? null : selector, browseOnly);
+ return null;
}
@Override
public void close() throws Exception {
Source source = (Source) protonSender.getSource();
- if (source != null && source.getAddress() != null && multicast) {
- SimpleString queueName =
SimpleString.toSimpleString(source.getAddress());
+ if (source != null && getSourceAddress(source) != null && multicast) {
Review Comment:
Given that getSourceAddress(source) handles null Source values, would seem
like this could be put in a variable here rather than potentially doing the
extraction twice as it is.
##########
artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/DefaultSenderController.java:
##########
@@ -207,6 +212,10 @@ public Consumer init(ProtonServerSenderContext
senderContext) throws Exception {
}
source.setAddress(queue.toString());
} else {
+ final String sourceAddress =
ParameterisedAddress.extractAddress(source.getAddress());
+
+ addressParameters =
ParameterisedAddress.extractParameters(source.getAddress());
Review Comment:
The method cant handle being passed a null, but its possible this value is
null.
I'd guess that might even explain the unit test failure (from an exception
type having changed, to an internal exception)
Issue Time Tracking
-------------------
Worklog Id: (was: 921932)
Time Spent: 20m (was: 10m)
> Add support for setting consumer priority on AMQP Receiver Source addresses
> ---------------------------------------------------------------------------
>
> Key: ARTEMIS-4792
> URL: https://issues.apache.org/jira/browse/ARTEMIS-4792
> Project: ActiveMQ Artemis
> Issue Type: New Feature
> Components: AMQP
> Affects Versions: 2.34.0
> Reporter: Timothy A. Bish
> Assignee: Timothy A. Bish
> Priority: Minor
> Fix For: 2.35.0
>
> Time Spent: 20m
> Remaining Estimate: 0h
>
> When creating a receiver link from a client the only way currently to adjust
> the consumer priority on the broker is to set a value in the receiver
> properties to indicate the desired priority. For some client AMQP client
> libraries this is not simple or not possible in the provided API. To solve
> this we can add support for parsing URI type options from the source address
> of the receiver attach and look for the option "consumer-priority" which is
> also used by the Core client to configure consumer priority (Openwire clients
> can do the same via an openwire client property "consumer.priority").
> This updates the client receiver attach to extract properties from the
> address the source which have the form:
> {code:java}
> address?consumer-priority=1{code}
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information, visit: https://activemq.apache.org/contact