|
1 | | -// Copyright (c) 2007-2020 VMware, Inc. or its affiliates. All rights reserved. |
| 1 | +// Copyright (c) 2007-2022 VMware, Inc. or its affiliates. All rights reserved. |
2 | 2 | // |
3 | 3 | // This software, the RabbitMQ Java client library, is triple-licensed under the |
4 | 4 | // Mozilla Public License 2.0 ("MPL"), the GNU General Public License version 2 |
|
23 | 23 | import com.rabbitmq.client.impl.DefaultExceptionHandler; |
24 | 24 | import com.rabbitmq.client.impl.nio.NioParams; |
25 | 25 | import io.micrometer.core.instrument.composite.CompositeMeterRegistry; |
| 26 | +import java.util.stream.Collectors; |
26 | 27 | import org.apache.commons.cli.*; |
27 | 28 | import org.slf4j.Logger; |
28 | 29 | import org.slf4j.LoggerFactory; |
@@ -756,22 +757,24 @@ static Map<String, Object> convertKeyValuePairs(String arg) { |
756 | 757 | if (arg == null || arg.trim().isEmpty()) { |
757 | 758 | return null; |
758 | 759 | } |
759 | | - Map<String, Object> properties = new HashMap<>(); |
760 | | - for (String entry : arg.split(",")) { |
| 760 | + return Arrays.stream(arg.split(",")).map(entry -> { |
761 | 761 | String [] keyValue = entry.split("="); |
762 | | - if (keyValue.length == 1 || |
763 | | - keyValue[0].equals("x-dead-letter-exchange") && |
764 | | - keyValue[1].equals("amq.default")) { |
765 | | - properties.put(keyValue[0], ""); |
| 762 | + if (keyValue.length == 1) { |
| 763 | + return new Object[] {keyValue[0], ""}; |
766 | 764 | } else { |
767 | 765 | try { |
768 | | - properties.put(keyValue[0], Long.parseLong(keyValue[1])); |
| 766 | + return new Object[] {keyValue[0], Long.parseLong(keyValue[1])}; |
769 | 767 | } catch(NumberFormatException e) { |
770 | | - properties.put(keyValue[0], keyValue[1]); |
| 768 | + return new Object[] {keyValue[0], keyValue[1]}; |
771 | 769 | } |
772 | 770 | } |
773 | | - } |
774 | | - return properties; |
| 771 | + }).map(keyValue -> { |
| 772 | + if ("x-dead-letter-exchange".equals(keyValue[0]) && "amq.default".equals(keyValue[1])) { |
| 773 | + return new String[] {"x-dead-letter-exchange", ""}; |
| 774 | + } else { |
| 775 | + return keyValue; |
| 776 | + } |
| 777 | + }).collect(Collectors.toMap(keyEntry -> keyEntry[0].toString(), keyEntry -> keyEntry[1])); |
775 | 778 | } |
776 | 779 |
|
777 | 780 | private static String getExchangeName(CommandLineProxy cmd, String def) { |
|
0 commit comments