This is an automated email from the ASF dual-hosted git repository. havret pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/activemq-nms-amqp.git
commit de438fb58ac000842559deb3ca559b44833deaa7 Author: Andreas Ländle <[email protected]> AuthorDate: Mon Apr 7 10:12:26 2025 +0000 Use `amqp.vost` to configure hostname and added some tests. --- docs/configuration.md | 5 ++++- src/NMS.AMQP/Meta/NmsConnectionInfo.cs | 2 +- src/NMS.AMQP/NmsConnectionFactory.cs | 9 ++++++--- src/NMS.AMQP/Provider/Amqp/AmqpConnection.cs | 2 +- test/Apache-NMS-AMQP-Test/ConnectionFactoryTest.cs | 8 ++++++-- 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index 4500d3b..c4f8ab7 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -18,7 +18,6 @@ The options apply to the behavior of the NMS objects such as Connection, Session - **nms.username** User name value used to authenticate the connection. - **nms.password** The password value used to authenticate the connection. - **nms.clientId** The ClientId value that is applied to the connection. -- **nms.hostname** Optional, the name of the host to which we are connecting. By default this value is derived from the URI. Can be used to determine the correct service if connecting to an AMQP proxy. - **nms.localMessageExpiry** Controls whether MessageConsumer instances will locally filter expired Messages or deliver them. By default this value is set to true and expired messages will be filtered. - **nms.sendTimeout** Timeout value that controls how long the client waits on completion of a synchronous message send before returning an error. By default the client will wait indefinitely for a send to complete. - **nms.requestTimeout** Timeout value that controls how long the client waits on completion of various synchronous interactions, such as opening a producer or consumer, before returning an error. Does not affect synchronous message sends. By default the client will wait indefinitely for a request to complete. @@ -31,6 +30,10 @@ The options apply to the behavior of the NMS objects such as Connection, Session - **nms.prefetchPolicy.queueBrowserPrefetch** Link credit value that will be assigned to new queue browser. The default value is 1000.. - **nms.prefetchPolicy.durableTopicPrefetch** Link credit value that will be assigned to new consumers of durable topic. The default value is 1000.. +### AMQP Configuration options + +- **amqp.vhost** Optional, the name of the host to which we are connecting. By default this value is derived from the URI. Can be used to determine the correct service if connecting to an AMQP proxy. + ### TCP Transport Configuration options When connected to a remote using plain TCP these options configure the behaviour of the underlying socket. These options are appended to the connection URI along with the other configuration options, for example: diff --git a/src/NMS.AMQP/Meta/NmsConnectionInfo.cs b/src/NMS.AMQP/Meta/NmsConnectionInfo.cs index dc56d3c..d498058 100644 --- a/src/NMS.AMQP/Meta/NmsConnectionInfo.cs +++ b/src/NMS.AMQP/Meta/NmsConnectionInfo.cs @@ -60,7 +60,7 @@ namespace Apache.NMS.AMQP.Meta public NmsConnectionId Id { get; } public bool IsExplicitClientId { get; private set; } public string ClientId { get; private set; } - public string HostName { get; set; } + public string VHost { get; set; } public string UserName { get; set; } public string Password { get; set; } public Uri ConfiguredUri { get; set; } diff --git a/src/NMS.AMQP/NmsConnectionFactory.cs b/src/NMS.AMQP/NmsConnectionFactory.cs index bd4935f..c35044a 100644 --- a/src/NMS.AMQP/NmsConnectionFactory.cs +++ b/src/NMS.AMQP/NmsConnectionFactory.cs @@ -169,11 +169,11 @@ namespace Apache.NMS.AMQP public string ClientId { get; set; } /// <summary> - /// Sets and gets the name of the host to which we are connecting. + /// Sets and gets the name of the virtual host to which we are connecting. /// By default this value is derived from the URI. /// Can be used to determine the correct service if connecting to an AMQP proxy. /// </summary> - public string HostName { get; set; } + public string VHost { get; set; } /// <summary> /// Sets and gets the prefetch values for consumers @@ -347,7 +347,7 @@ namespace Apache.NMS.AMQP { UserName = userName, Password = password, - HostName = HostName, + VHost = VHost, ConfiguredUri = BrokerUri, RequestTimeout = RequestTimeout, SendTimeout = SendTimeout, @@ -375,6 +375,9 @@ namespace Apache.NMS.AMQP { StringDictionary nmsOptions = PropertyUtil.FilterProperties(options, "nms."); PropertyUtil.SetProperties(this, nmsOptions); + + StringDictionary amqpOptions = PropertyUtil.FilterProperties(options, "amqp."); + PropertyUtil.SetProperties(this, amqpOptions); // TODO: Check if there are any unused options, if so throw argument exception } diff --git a/src/NMS.AMQP/Provider/Amqp/AmqpConnection.cs b/src/NMS.AMQP/Provider/Amqp/AmqpConnection.cs index 107c31d..bbb333d 100644 --- a/src/NMS.AMQP/Provider/Amqp/AmqpConnection.cs +++ b/src/NMS.AMQP/Provider/Amqp/AmqpConnection.cs @@ -114,7 +114,7 @@ namespace Apache.NMS.AMQP.Provider.Amqp open.ContainerId = Info.ClientId; open.ChannelMax = Info.ChannelMax; open.MaxFrameSize = (uint) Info.MaxFrameSize; - open.HostName = String.IsNullOrEmpty(Info.HostName) ? remoteUri.Host : Info.HostName; + open.HostName = String.IsNullOrEmpty(Info.VHost) ? remoteUri.Host : Info.VHost; open.IdleTimeOut = (uint) Info.IdleTimeOut; open.DesiredCapabilities = new[] { diff --git a/test/Apache-NMS-AMQP-Test/ConnectionFactoryTest.cs b/test/Apache-NMS-AMQP-Test/ConnectionFactoryTest.cs index 6c62465..0b2b361 100644 --- a/test/Apache-NMS-AMQP-Test/ConnectionFactoryTest.cs +++ b/test/Apache-NMS-AMQP-Test/ConnectionFactoryTest.cs @@ -93,7 +93,8 @@ namespace NMS.AMQP.Test "&nms.requestTimeout=1000" + "&nms.sendTimeout=1000" + "&nms.localMessageExpiry=false" + - "&nms.maxNewConnectionRatePerSec=4"; + "&nms.maxNewConnectionRatePerSec=4" + + "&amqp.vhost=test-vhost"; NmsConnectionFactory factory = new NmsConnectionFactory(configuredUri); @@ -105,6 +106,7 @@ namespace NMS.AMQP.Test Assert.AreEqual(1000, factory.RequestTimeout); Assert.AreEqual(1000, factory.SendTimeout); Assert.AreEqual(4, factory.MaxNewConnectionRatePerSec); + Assert.AreEqual("test-vhost", factory.VHost); Assert.IsFalse(factory.LocalMessageExpiry); } @@ -122,7 +124,8 @@ namespace NMS.AMQP.Test "&nms.sendTimeout=1000" + "&nms.closeTimeout=2000" + "&nms.localMessageExpiry=false" + - "&nms.prefetchPolicy.all=55"; + "&nms.prefetchPolicy.all=55" + + "&amqp.vhost=test-vhost"; NmsConnectionFactory factory = new NmsConnectionFactory(new Uri(configuredUri)); @@ -138,6 +141,7 @@ namespace NMS.AMQP.Test Assert.AreEqual(55, factory.PrefetchPolicy.TopicPrefetch); Assert.AreEqual(55, factory.PrefetchPolicy.DurableTopicPrefetch); Assert.AreEqual(55, factory.PrefetchPolicy.QueueBrowserPrefetch); + Assert.AreEqual("test-vhost", factory.VHost); Assert.IsFalse(factory.LocalMessageExpiry); } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] For further information, visit: https://activemq.apache.org/contact
