Skip to content

Commit 537e571

Browse files
authored
Merge pull request #7 from elmuerte/master
Exclude self from static cluster connectors
2 parents 213248c + 61554c4 commit 537e571

File tree

4 files changed

+47
-2
lines changed

4 files changed

+47
-2
lines changed

REFERENCE.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ The following parameters are available in the `activemq::instance` defined type:
407407
* [`address_settings`](#-activemq--instance--address_settings)
408408
* [`addresses`](#-activemq--instance--addresses)
409409
* [`allow_failback`](#-activemq--instance--allow_failback)
410+
* [`allow_direct_connections_only`](#-activemq--instance--allow_direct_connections_only)
410411
* [`bind`](#-activemq--instance--bind)
411412
* [`broadcast_groups`](#-activemq--instance--broadcast_groups)
412413
* [`broker_plugins`](#-activemq--instance--broker_plugins)
@@ -478,6 +479,16 @@ Data type: `Boolean`
478479

479480
Should stop backup on live restart.
480481

482+
##### <a name="-activemq--instance--allow_direct_connections_only"></a>`allow_direct_connections_only`
483+
484+
Data type: `Optional[Boolean]`
485+
486+
When using `static` for [`server_discovery`](#-activemq--server_discovery)
487+
only make connections to the defined connectors and not any other
488+
broker in the cluser.
489+
490+
Default value: `true`
491+
481492
##### <a name="-activemq--instance--bind"></a>`bind`
482493

483494
Data type: `String`

manifests/instance.pp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
# @param allow_failback
2121
# Should stop backup on live restart.
2222
#
23+
# @param allow_direct_connections_only
24+
# When using static server discovery only make connections to the
25+
# defined connectors and not any other broker in the cluser.
26+
#
2327
# @param bind
2428
# Configure which IP address to listen on. Should be either a FQDN
2529
# or an IP address.
@@ -167,6 +171,7 @@
167171
String $java_xms = $activemq::java_xms,
168172
String $java_xmx = $activemq::java_xmx,
169173
# Optional parameters
174+
Optional[Boolean] $allow_direct_connections_only = true,
170175
Optional[Integer] $global_max_size_mb = undef,
171176
Optional[String] $group = undef,
172177
Optional[Boolean] $service_enable = undef,
@@ -379,6 +384,7 @@
379384
'address_settings' => $address_settings,
380385
'addresses' => $addresses,
381386
'allow_failback' => $allow_failback,
387+
'allow_direct_connections_only' => $allow_direct_connections_only,
382388
'bind' => $bind,
383389
'broadcast_groups' => $broadcast_groups,
384390
'broker_plugins' => $_broker_plugins,

spec/acceptance/activemq_spec.rb

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
require 'spec_helper_acceptance'
22

3+
RSpec::Matchers.define_negated_matcher :not_match, :match
4+
35
describe 'activemq' do
46
let(:activemq_checksum) { 'a73331cb959bb0ba9667414682c279bc9ce2aec4c8fecbcdee4670bf9d63bf66010c8c55a6b727b1ad6d51bbccadd663b96a70b867721d9388d54a9391c6af85' }
57
let(:activemq_group) { 'activemq' }
@@ -41,13 +43,28 @@
4143
admin_password => '#{activemq_instance_password}',
4244
admin_user => '#{activemq_instance_user}',
4345
checksum => '#{activemq_checksum}',
44-
cluster => false,
46+
cluster => true,
47+
cluster_password => '#{activemq_instance_password}',
48+
cluster_user => '#{activemq_instance_user}',
49+
cluster_name => 'activemq-cluster',
50+
cluster_topology => {
51+
'#{activemq_instance_name}' => {
52+
target_host => 'localhost',
53+
bind => '127.0.0.1',
54+
},
55+
'instance2' => {
56+
target_host => 'localhost',
57+
bind => '127.0.0.2',
58+
}
59+
},
60+
server_discovery => 'static',
4561
download_url => 'http://archive.apache.org/dist/activemq/activemq-artemis/#{activemq_version}/%s',
4662
instances => {
4763
'#{activemq_instance_name}' => {
4864
bind => '127.0.0.1',
4965
port => 61616,
5066
web_port => 8161,
67+
ha_policy => 'live-only',
5168
acceptors => {
5269
artemis => { port => 61616 },
5370
amqp => { port => 5672 },
@@ -72,6 +89,14 @@
7289
it { expect(file("#{activemq_instance_base}/#{activemq_instance_name}/etc/artemis.profile").content).to match(%r{^ARTEMIS_HOME}) }
7390
it { expect(file("#{activemq_instance_base}/#{activemq_instance_name}/etc/artemis.profile").content).to match(%r{^JAVA_ARGS}) }
7491

92+
# Test that 'artemis-instance1' is not in the static-connectors list
93+
it {
94+
expect(file("#{activemq_instance_base}/#{activemq_instance_name}/etc/broker.xml").content.gsub(%r{.*<static-connectors[^>]*>(.*)</static-connectors>.*}ms, '\1'))
95+
.to match(%r{instance2})
96+
.and not_match(%r{:activemq_instance_name})
97+
}
98+
it { expect(file("#{activemq_instance_base}/#{activemq_instance_name}/etc/broker.xml").content).to match(%r{allow-direct-connections-only="true"}) }
99+
75100
it 'sets up the service' do
76101
expect(service("activemq@#{activemq_instance_name}")).to be_running
77102
expect(service("activemq@#{activemq_instance_name}")).to be_enabled

templates/broker.xml.epp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,12 @@ under the License.
148148
<message-load-balancing><%= $message_load_balancing %></message-load-balancing>
149149
<max-hops><%= $max_hops %></max-hops>
150150
<% if $activemq::server_discovery == 'static' { -%>
151-
<static-connectors allow-direct-connections-only="true">
151+
<static-connectors allow-direct-connections-only="<%= $allow_direct_connections_only %>">
152152
<% $connectors.each |$key, $value| { -%>
153+
<%# # Do not add the connector that matches the name of this instance. -%>
154+
<% if ($key != "artemis-${name}") { -%>
153155
<connector-ref><%= $key %></connector-ref>
156+
<% } -%>
154157
<% } -%>
155158
</static-connectors>
156159
<% } -%>

0 commit comments

Comments
 (0)