Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Cluster support

  • Loading branch information...
commit 28e88b3a66a29cdca2479caaaf1c13784306c7c5 1 parent 55c14a2
@jkff jkff authored
View
14 README.md
@@ -37,6 +37,20 @@ Class for installing rabbitmq-server:
delete_guest_user => true,
}
+### Clustering
+To use RabbitMQ clustering and H/A facilities, use the rabbitmq::server
+parameters `config_cluster` and `cluster_disk_nodes`, e.g.:
+
+ class { 'rabbitmq::server':
+ config_cluster => true,
+ cluster_disk_nodes => ['rabbit1', 'rabbit2'],
+ }
+
+Currently all cluster nodes are registered as disk nodes (not ram).
+
+**NOTE:** You still need to use `x-ha-policy: all` in your client
+applications for any particular queue to take advantage of H/A, this module
+merely clusters RabbitMQ instances.
## Native Types
View
44 manifests/server.pp
@@ -13,6 +13,14 @@
# [*node_ip_address*] - ip address for rabbitmq to bind to
# [*config*] - contents of config file
# [*env_config*] - contents of env-config file
+# [*config_cluster*] - whether to configure a RabbitMQ cluster
+# [*cluster_disk_nodes*] - which nodes to cluster with (including the current one)
+# [*erlang_cookie*] - erlang cookie, must be the same for all nodes in a cluster
+# [*wipe_db_on_cookie_change*] - whether to wipe the RabbitMQ data if the specified
+# erlang_cookie differs from the current one. This is a sad parameter: actually,
+# if the cookie indeed differs, then wiping the database is the *only* thing you
+# can do. You're only required to set this parameter to true as a sign that you
+# realise this.
# Requires:
# stdlib
# Sample Usage:
@@ -30,9 +38,13 @@
$service_ensure = 'running',
$config_stomp = false,
$stomp_port = '6163',
+ $config_cluster = false,
+ $cluster_disk_nodes = [],
$node_ip_address = 'UNSET',
$config='UNSET',
- $env_config='UNSET'
+ $env_config='UNSET',
+ $erlang_cookie='EOKOWXQREETZSHFNTPEY',
+ $wipe_db_on_cookie_change=false
) {
validate_bool($delete_guest_user, $config_stomp)
@@ -79,8 +91,36 @@
owner => '0',
group => '0',
mode => '0644',
+ require => Package[$package_name],
notify => Class['rabbitmq::service'],
- require => Package[$package_name]
+ }
+
+ if $config_cluster {
+ file { 'erlang_cookie':
+ path =>"/var/lib/rabbitmq/.erlang.cookie",
+ owner => rabbitmq,
+ group => rabbitmq,
+ mode => '0400',
+ content => $erlang_cookie,
+ replace => true,
+ before => File['rabbitmq.config'],
+ require => Exec['wipe_db'],
+ }
+ # require authorize_cookie_change
+
+ if $wipe_db_on_cookie_change {
+ exec { 'wipe_db':
+ command => '/etc/init.d/rabbitmq-server stop; /bin/rm -rf /var/lib/rabbitmq/mnesia',
+ require => Package[$package_name],
+ unless => "/bin/grep -qx ${erlang_cookie} /var/lib/rabbitmq/.erlang.cookie"
+ }
+ } else {
+ exec { 'wipe_db':
+ command => '/bin/false "Cookie must be changed but wipe_db is false"', # If the cookie doesn't match, just fail.
+ require => Package[$package_name],
+ unless => "/bin/grep -qx ${erlang_cookie} /var/lib/rabbitmq/.erlang.cookie"
+ }
+ }
}
file { 'rabbitmq-env.config':
View
32 spec/classes/rabbitmq_server_spec.rb
@@ -68,7 +68,7 @@
describe 'not configuring stomp by default' do
it 'should not specify stomp parameters in rabbitmq.config' do
verify_contents(subject, 'rabbitmq.config',
- ['[].'])
+ ['[','].'])
end
end
@@ -80,9 +80,37 @@
end
it 'should specify stomp port in rabbitmq.config' do
verify_contents(subject, 'rabbitmq.config',
- ['[ {rabbitmq_stomp, [{tcp_listeners, [5679]} ]} ].'])
+ ['[','{rabbitmq_stomp, [{tcp_listeners, [5679]} ]}','].'])
end
end
+ describe 'configuring cluster' do
+ let :params do
+ { :config_cluster => true,
+ :cluster_disk_nodes => ['hare-1', 'hare-2']
+ }
+ end
+ it 'should specify cluster nodes in rabbitmq.config' do
+ verify_contents(subject, 'rabbitmq.config',
+ ['[',"{rabbit, [{cluster_nodes, ['rabbit@hare-1', 'rabbit@hare-2']}]}", '].'])
+ end
+ it 'should have the default erlang cookie' do
+ verify_contents(subject, 'erlang_cookie',
+ ['EOKOWXQREETZSHFNTPEY'])
+ end
+
+ end
+
+ describe 'specifying custom erlang cookie in cluster mode' do
+ let :params do
+ { :config_cluster => true,
+ :erlang_cookie => 'YOKOWXQREETZSHFNTPEY' }
+ end
+ it 'should set .erlang.cookie to the specified value' do
+ verify_contents(subject, 'erlang_cookie',
+ ['YOKOWXQREETZSHFNTPEY'])
+ end
+ end
+
end
View
0  spec/fixtures/manifests/site.pp
No changes.
View
9 templates/rabbitmq.config
@@ -1,9 +1,12 @@
% This file managed by Puppet <%= puppetversion %>
% Template Path: <%= module_name %>/templates/rabbitmq.config
+[
+<% if config_cluster -%>
+{rabbit, [{cluster_nodes, [<%= cluster_disk_nodes.map { |n| "\'rabbit@#{n}\'" }.join(', ') %>]}]}<% if config_stomp -%>,<% end %>
+<% end -%>
<% if config_stomp -%>
% Configure the Stomp Plugin listening port
-[ {rabbitmq_stomp, [{tcp_listeners, [<%= stomp_port %>]} ]} ].
-<% else -%>
-[].
+{rabbitmq_stomp, [{tcp_listeners, [<%= stomp_port %>]} ]}
<% end -%>
+].
% EOF
Please sign in to comment.
Something went wrong with that request. Please try again.