diff --git a/REFERENCE.md b/REFERENCE.md index 6f1dc2a..b557320 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -407,6 +407,7 @@ The following parameters are available in the `activemq::instance` defined type: * [`address_settings`](#-activemq--instance--address_settings) * [`addresses`](#-activemq--instance--addresses) * [`allow_failback`](#-activemq--instance--allow_failback) +* [`allow_direct_connections_only`](#-activemq--instance--allow_direct_connections_only) * [`bind`](#-activemq--instance--bind) * [`broadcast_groups`](#-activemq--instance--broadcast_groups) * [`broker_plugins`](#-activemq--instance--broker_plugins) @@ -478,6 +479,16 @@ Data type: `Boolean` Should stop backup on live restart. +##### `allow_direct_connections_only` + +Data type: `Optional[Boolean]` + +When using `static` for [`server_discovery`](#-activemq--server_discovery) +only make connections to the defined connectors and not any other +broker in the cluser. + +Default value: `true` + ##### `bind` Data type: `String` diff --git a/manifests/instance.pp b/manifests/instance.pp index f5ab554..4aa4ee9 100644 --- a/manifests/instance.pp +++ b/manifests/instance.pp @@ -20,6 +20,10 @@ # @param allow_failback # Should stop backup on live restart. # +# @param allow_direct_connections_only +# When using static server discovery only make connections to the +# defined connectors and not any other broker in the cluser. +# # @param bind # Configure which IP address to listen on. Should be either a FQDN # or an IP address. @@ -167,6 +171,7 @@ String $java_xms = $activemq::java_xms, String $java_xmx = $activemq::java_xmx, # Optional parameters + Optional[Boolean] $allow_direct_connections_only = true, Optional[Integer] $global_max_size_mb = undef, Optional[String] $group = undef, Optional[Boolean] $service_enable = undef, @@ -379,6 +384,7 @@ 'address_settings' => $address_settings, 'addresses' => $addresses, 'allow_failback' => $allow_failback, + 'allow_direct_connections_only' => $allow_direct_connections_only, 'bind' => $bind, 'broadcast_groups' => $broadcast_groups, 'broker_plugins' => $_broker_plugins, diff --git a/spec/acceptance/activemq_spec.rb b/spec/acceptance/activemq_spec.rb index 446d2e5..0e3a1a3 100644 --- a/spec/acceptance/activemq_spec.rb +++ b/spec/acceptance/activemq_spec.rb @@ -1,5 +1,7 @@ require 'spec_helper_acceptance' +RSpec::Matchers.define_negated_matcher :not_match, :match + describe 'activemq' do let(:activemq_checksum) { 'a73331cb959bb0ba9667414682c279bc9ce2aec4c8fecbcdee4670bf9d63bf66010c8c55a6b727b1ad6d51bbccadd663b96a70b867721d9388d54a9391c6af85' } let(:activemq_group) { 'activemq' } @@ -41,13 +43,28 @@ admin_password => '#{activemq_instance_password}', admin_user => '#{activemq_instance_user}', checksum => '#{activemq_checksum}', - cluster => false, + cluster => true, + cluster_password => '#{activemq_instance_password}', + cluster_user => '#{activemq_instance_user}', + cluster_name => 'activemq-cluster', + cluster_topology => { + '#{activemq_instance_name}' => { + target_host => 'localhost', + bind => '127.0.0.1', + }, + 'instance2' => { + target_host => 'localhost', + bind => '127.0.0.2', + } + }, + server_discovery => 'static', download_url => 'http://archive.apache.org/dist/activemq/activemq-artemis/#{activemq_version}/%s', instances => { '#{activemq_instance_name}' => { bind => '127.0.0.1', port => 61616, web_port => 8161, + ha_policy => 'live-only', acceptors => { artemis => { port => 61616 }, amqp => { port => 5672 }, @@ -72,6 +89,14 @@ it { expect(file("#{activemq_instance_base}/#{activemq_instance_name}/etc/artemis.profile").content).to match(%r{^ARTEMIS_HOME}) } it { expect(file("#{activemq_instance_base}/#{activemq_instance_name}/etc/artemis.profile").content).to match(%r{^JAVA_ARGS}) } + # Test that 'artemis-instance1' is not in the static-connectors list + it { + expect(file("#{activemq_instance_base}/#{activemq_instance_name}/etc/broker.xml").content.gsub(%r{.*]*>(.*).*}ms, '\1')) + .to match(%r{instance2}) + .and not_match(%r{:activemq_instance_name}) + } + it { expect(file("#{activemq_instance_base}/#{activemq_instance_name}/etc/broker.xml").content).to match(%r{allow-direct-connections-only="true"}) } + it 'sets up the service' do expect(service("activemq@#{activemq_instance_name}")).to be_running expect(service("activemq@#{activemq_instance_name}")).to be_enabled diff --git a/templates/broker.xml.epp b/templates/broker.xml.epp index 41a32d6..b3dcd16 100644 --- a/templates/broker.xml.epp +++ b/templates/broker.xml.epp @@ -148,9 +148,12 @@ under the License. <%= $message_load_balancing %> <%= $max_hops %> <% if $activemq::server_discovery == 'static' { -%> - + <% $connectors.each |$key, $value| { -%> +<%# # Do not add the connector that matches the name of this instance. -%> +<% if ($key != "artemis-${name}") { -%> <%= $key %> +<% } -%> <% } -%> <% } -%>