Skip to content

Instantly share code, notes, and snippets.

@Filirom1
Last active December 27, 2015 13:39
Show Gist options
  • Save Filirom1/7334311 to your computer and use it in GitHub Desktop.
Save Filirom1/7334311 to your computer and use it in GitHub Desktop.

Install routing plugin

yum install rubygem-openshift-origin-routing-activemq.noarch

Create routing-plugin configuration file

cp /etc/openshift/plugins.d/openshift-origin-routing-activemq.conf.example /etc/openshift/plugins.d/openshift-origin-routing-activemq.conf

Add routinginfo user into activemq.xml configuration file. See files below.

Restart broker and activemq

/etc/init.d/openshift-broker restart
/etc/init.d/activemq restart

Allow ha and custom ssl certificates for your user

oo-admin-ctl-user -l admin --allowha true
oo-admin-ctl-user -l admin --allowprivatesslcertificates true

Run ActiveMq listener. See file below.

scl enable ruby193 "ruby topic_listener.rb" &

Create an application and check routing message

[root@broker ~]# scl enable ruby193 "rhc create-app --app appname --type php-5.
Application Options
-------------------
  Domain:     test
  Cartridges: php-5.3
  Gear Size:  default
  Scaling:    yes

Creating application 'appname' ... done


Waiting for your DNS name to be available ... done

Initialized empty Git repository in /root/appname/.git/
The authenticity of host 'appname-test.example.com (10.34.60.50)' can't be established.
RSA key fingerprint is be:d2:e3:52:5d:46:2e:f8:22:fd:8b:f6:18:94:65:60.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'appname-test.example.com' (RSA) to the list of known hosts.

Your application 'appname' is now available.

  URL:        http://appname-test.example.com/
  SSH to:     [email protected]
  Git remote: ssh://[email protected]/~/git/appname.git/
  Cloned to:  /root/appname

Run 'rhc show-app appname' for more details about your app.

<Stomp::Message headers={"content-type"=>"text/plain; charset=UTF-8", "message-id"=>"ID:broker.example.com-34735-1383665653444-3:2:-1:1:18", "destination"=>"/topic/routinginfo", "timestamp"=>"1383734208660", "expires"=>"0", "content-length"=>"69", "priority"=>"4"} body='---
:action: :create_application
:app_name: appname
:namespace: test
' command='MESSAGE' >

Make your application HA and check routing message. We have 2 php and 2 haproxy with their IP and port.

curl -H"Content-Type:application/json"  -XPOST -d '{"event":"make-ha"}' -u "admin:admin" -k https://broker.example.com/broker/rest/application/527a1bc06892dff71c0000ba/events |scl enable nodejs010 "json"

<Stomp::Message headers={"content-type"=>"text/plain; charset=UTF-8", "message-id"=>"ID:broker.example.com-34735-1383665653444-3:2:-1:1:19", "destination"=>"/topic/routinginfo", "timestamp"=>"1383734606254", "expires"=>"0", "content-length"=>"259", "priority"=>"4"} body='---
:action: :add_gear
:app_name: appname
:namespace: test
:public_port_name: php-5.3
:public_address: 10.34.60.50
:public_port: '38056'
:protocols:
- http
- ws
:types:
- web_framework
:mappings:
- frontend: ''
  backend: ''
- frontend: /health
  backend: ''
' command='MESSAGE' >

<Stomp::Message headers={"content-type"=>"text/plain; charset=UTF-8", "message-id"=>"ID:broker.example.com-34735-1383665653444-3:2:-1:1:20", "destination"=>"/topic/routinginfo", "timestamp"=>"1383734606336", "expires"=>"0", "content-length"=>"282", "priority"=>"4"} body='---
:action: :add_gear
:app_name: appname
:namespace: test
:public_port_name: haproxy-1.4
:public_address: 10.34.60.50
:public_port: '38057'
:protocols:
- http
- ws
:types:
- load_balancer
:mappings:
- frontend: ''
  backend: ''
- frontend: /health
  backend: /configuration/health
' command='MESSAGE' >

<Stomp::Message headers={"content-type"=>"text/plain; charset=UTF-8", "message-id"=>"ID:broker.example.com-34735-1383665653444-3:2:-1:1:21", "destination"=>"/topic/routinginfo", "timestamp"=>"1383734606458", "expires"=>"0", "content-length"=>"259", "priority"=>"4"} body='---
:action: :add_gear
:app_name: appname
:namespace: test
:public_port_name: php-5.3
:public_address: 10.34.60.50
:public_port: '38061'
:protocols:
- http
- ws
:types:
- web_framework
:mappings:
- frontend: ''
  backend: ''
- frontend: /health
  backend: ''
' command='MESSAGE' >

<Stomp::Message headers={"content-type"=>"text/plain; charset=UTF-8", "message-id"=>"ID:broker.example.com-34735-1383665653444-3:2:-1:1:22", "destination"=>"/topic/routinginfo", "timestamp"=>"1383734606518", "expires"=>"0", "content-length"=>"282", "priority"=>"4"} body='---
:action: :add_gear
:app_name: appname
:namespace: test
:public_port_name: haproxy-1.4
:public_address: 10.34.60.50
:public_port: '38062'
:protocols:
- http
- ws
:types:
- load_balancer
:mappings:
- frontend: ''
  backend: ''
- frontend: /health
  backend: /configuration/health
' command='MESSAGE' >

Scale up your application and check routing message

scl enable ruby193 "rhc scale-cartridge --app appname --min 3 --cartridge php-5.3"
This operation will run until the application is at the minimum scale and may take several minutes.
Setting scale range for php-5.3 ... done

php-5.3 (PHP 5.3)
-----------------
  Scaling: x3 (minimum: 3, maximum: available) on small gears

<Stomp::Message headers={"content-type"=>"text/plain; charset=UTF-8", "message-id"=>"ID:broker.example.com-34735-1383665653444-3:2:-1:1:23", "destination"=>"/topic/routinginfo", "timestamp"=>"1383734934124", "expires"=>"0", "content-length"=>"259", "priority"=>"4"} body='---
:action: :add_gear
:app_name: appname
:namespace: test
:public_port_name: php-5.3
:public_address: 10.34.60.50
:public_port: '38066'
:protocols:
- http
- ws
:types:
- web_framework
:mappings:
- frontend: ''
  backend: ''
- frontend: /health
  backend: ''
' command='MESSAGE' >

Scale down your application and check routing message

scl enable ruby193 "rhc scale-cartridge --app appname --min 2 --max 2 --cartridge php-5.3"
This operation will run until the application is at the minimum scale and may take several minutes.
Setting scale range for php-5.3 ... done

php-5.3 (PHP 5.3)
-----------------
  Scaling: x2 (minimum: 2, maximum: 2) on small gears

<Stomp::Message headers={"content-type"=>"text/plain; charset=UTF-8", "message-id"=>"ID:broker.example.com-34735-1383665653444-3:2:-1:1:24", "destination"=>"/topic/routinginfo", "timestamp"=>"1383735015263", "expires"=>"0", "content-length"=>"113", "priority"=>"4"} body='---
:action: :delete_gear
:app_name: appname
:namespace: test
:public_address: 10.34.60.50
:public_port: '38066'
' command='MESSAGE' >

Add an alias to your application and check routing message

scl enable ruby193 "rhc alias add --app appname alias.com"
Alias 'alias.com' has been added.
<Stomp::Message headers={"content-type"=>"text/plain; charset=UTF-8", "message-id"=>"ID:broker.example.com-34735-1383665653444-3:2:-1:1:25", "destination"=>"/topic/routinginfo", "timestamp"=>"1383735129691", "expires"=>"0", "content-length"=>"78", "priority"=>"4"} body='---
:action: :add_alias
:app_name: appname
:namespace: test
:alias: alias.com
' command='MESSAGE' >

Add a certificate and check routing message

openssl genrsa -des3 -out server.key 1024
openssl req -new -key server.key -out server.csr
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

scl enable ruby193 "rhc alias-update-cert alias.com --certificate server.crt --private-key server.key --passphrase pass --app appname"
SSL certificate successfully added.

<Stomp::Message headers={"content-type"=>"text/plain; charset=UTF-8", "message-id"=>"ID:broker.example.com-34735-1383665653444-3:2:-1:1:26", "destination"=>"/topic/routinginfo", "timestamp"=>"1383735425978", "expires"=>"0", "content-length"=>"1923", "priority"=>"4"} body='---
:action: :add_ssl
:app_name: appname
:namespace: test
:alias: alias.com
:ssl: ! '-----BEGIN CERTIFICATE-----

  MIIB+zCCAWQCCQCb2osPF/G4TzANBgkqhkiG9w0BAQUFADBCMQswCQYDVQQGEwJY

  WDEVMBMGA1UEBwwMRGVmYXVsdCBDaXR5MRwwGgYDVQQKDBNEZWZhdWx0IENvbXBh

  bnkgTHRkMB4XDTEzMTEwNjEwNTYxNloXDTE0MTEwNjEwNTYxNlowQjELMAkGA1UE

  BhMCWFgxFTATBgNVBAcMDERlZmF1bHQgQ2l0eTEcMBoGA1UECgwTRGVmYXVsdCBD

  b21wYW55IEx0ZDCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAzHuCrE5az8Hd

  EfP8ZinHbFB5TYhmi6RF4xiTPCvG6v4ZrF13Bt85oJy8o24knSMF69c/LTWAFOjX

  bQUe8CxOzz/WDAPSU+FyosrjwyeQXFuodqQV/iMZz66JhBKZTnkTNQbKpEN8SCc6

  PXahPRe/ZpZtj5BvNusw1Ip7khY7cs8CAwEAATANBgkqhkiG9w0BAQUFAAOBgQCC

  4cgZ0fpnDHFNQVWUcvCsAJkgATmq10KWVzRnaSm1zNGZCaAhhqHKCTKXh3foIzMt

  SrysvYTEC6etJ5/nzKcIbqn600mJz/JV282onRcBc5KCQ7GYWj5TU9vwq/Dtg5jd

  LdlEC33I076DprX4BalnO9lmrWeld653M/Cm2Yi0rA==

  -----END CERTIFICATE-----

'
:private_key: ! '-----BEGIN RSA PRIVATE KEY-----

  Proc-Type: 4,ENCRYPTED

  DEK-Info: DES-EDE3-CBC,797B69DB94B73490


  tM3D43dzyUeSqLUWvVvdvryU8geb4K/nulWCPU4M2vKd3Gm7jt8ObcfzPaqqIoRf

  ML98/d1aWM9jZ2LVKHpAU+o6hwbinuoz9pYIO2ms+mN+kbgCQLw0qZbEAWTzus7W

  ocTaMlUJ+wfe0AnjMYsmYSISmIYGD6ookd3i8sElG1e9aiv7ELKyNIGgCu+XGjmU

  00VAg5PCLE4jXe7+3SVtSSsamebIAVMqqQ5v2DefB/00cd5KsWn5bedL/CkcpNTe

  0Tuhmlw7C7jXuIvkjC3TGiH+YBLcBAFTWSiyLyMcJ3irKmMq5rk2IzXRR/H7EdMb

  SWjCOUvOe7Yc4EKB+1C+7UXIT7uBGwEyGTfOF/R67E1IqMNzpjJGLfCFmH9rNfTq

  DpVRecAlCmLqiJGClxpfCLbZqfZjT3CvvTN3j9bpPij5693wVXmh7p/+2dhXddB1

  38um0COvJUDcw3j0kEaVIU/Xz8o8WmcJq4rEUDC/6YjwPwQ3HFUwMGNFLcf00a3N

  3x0k4CTWpc5N0yaag/aduim4tuYCC0sR0XssVY8ah/xEzsc56qXvwA5zeGNmp4ne

  lWUYE+hxGXiA7EqO2Rz1Ul5Bt+jLw1ekY0GKjFLURx7Ow/4Fk/+FHV7OBRTCJfSR

  zZD39v84j3swt0GGxYCsgt2slijao5EOs1WvpK5lh0ZFYdobH9OwFnkhgvp6z8TL

  wHelyjToWqWlM9fJ4PvevgyLT60CViuSaGnCjPLnavoMPhKBUY9L2W4bfiKcKX5S

  wjQyQ8wlSMsMgVGvw6Q9bb75Xdk9REQDgiGPLpETB8FJIKTfhEQcng==

  -----END RSA PRIVATE KEY-----

'
:pass_phrase: pass
' command='MESSAGE' >

Delete certificate and check routing message

scl enable ruby193 "rhc alias delete-cert --app appname alias.com"
This is a non-reversible action! Your SSL certificate will be permanently deleted from application 'appname'.

Are you sure you want to delete the SSL certificate? (yes|no): yes

SSL certificate successfully deleted.
<Stomp::Message headers={"content-type"=>"text/plain; charset=UTF-8", "message-id"=>"ID:broker.example.com-34735-1383665653444-3:2:-1:1:27", "destination"=>"/topic/routinginfo", "timestamp"=>"1383735584630", "expires"=>"0", "content-length"=>"79", "priority"=>"4"} body='---
:action: :remove_ssl
:app_name: appname
:namespace: test
:alias: alias.com
' command='MESSAGE' >

Remove an alias and check routing message

scl enable ruby193 "rhc alias-remove --app appname alias.com"
Alias 'alias.com' has been removed.

<Stomp::Message headers={"content-type"=>"text/plain; charset=UTF-8", "message-id"=>"ID:broker.example.com-34735-1383665653444-3:2:-1:1:28", "destination"=>"/topic/routinginfo", "timestamp"=>"1383735631348", "expires"=>"0", "content-length"=>"81", "priority"=>"4"} body='---
:action: :remove_alias
:app_name: appname
:namespace: test
:alias: alias.com
' command='MESSAGE' >

Delete an application and check routing message

scl enable ruby193 "rhc app-delete --app appname"
This is a non-reversible action! Your application code and data will be permanently deleted if you continue!

Are you sure you want to delete the application 'appname'? (yes|no): yes

Deleting application 'appname' ... deleted

<Stomp::Message headers={"content-type"=>"text/plain; charset=UTF-8", "message-id"=>"ID:broker.example.com-34735-1383665653444-3:2:-1:1:29", "destination"=>"/topic/routinginfo", "timestamp"=>"1383735707725", "expires"=>"0", "content-length"=>"113", "priority"=>"4"} body='---
:action: :delete_gear
:app_name: appname
:namespace: test
:public_address: 10.34.60.50
:public_port: '38056'
' command='MESSAGE' >

<Stomp::Message headers={"content-type"=>"text/plain; charset=UTF-8", "message-id"=>"ID:broker.example.com-34735-1383665653444-3:2:-1:1:30", "destination"=>"/topic/routinginfo", "timestamp"=>"1383735707731", "expires"=>"0", "content-length"=>"113", "priority"=>"4"} body='---
:action: :delete_gear
:app_name: appname
:namespace: test
:public_address: 10.34.60.50
:public_port: '38057'
' command='MESSAGE' >

<Stomp::Message headers={"content-type"=>"text/plain; charset=UTF-8", "message-id"=>"ID:broker.example.com-34735-1383665653444-3:2:-1:1:31", "destination"=>"/topic/routinginfo", "timestamp"=>"1383735709601", "expires"=>"0", "content-length"=>"113", "priority"=>"4"} body='---
:action: :delete_gear
:app_name: appname
:namespace: test
:public_address: 10.34.60.50
:public_port: '38061'
' command='MESSAGE' >

<Stomp::Message headers={"content-type"=>"text/plain; charset=UTF-8", "message-id"=>"ID:broker.example.com-34735-1383665653444-3:2:-1:1:32", "destination"=>"/topic/routinginfo", "timestamp"=>"1383735709608", "expires"=>"0", "content-length"=>"113", "priority"=>"4"} body='---
:action: :delete_gear
:app_name: appname
:namespace: test
:public_address: 10.34.60.50
:public_port: '38062'
' command='MESSAGE' >

<Stomp::Message headers={"content-type"=>"text/plain; charset=UTF-8", "message-id"=>"ID:broker.example.com-34735-1383665653444-3:2:-1:1:33", "destination"=>"/topic/routinginfo", "timestamp"=>"1383735710063", "expires"=>"0", "content-length"=>"69", "priority"=>"4"} body='---
:action: :delete_application
:app_name: appname
:namespace: test
' command='MESSAGE' >

<!-- add users for mcollective -->
<plugins>
<statisticsBrokerPlugin/>
<simpleAuthenticationPlugin>
<users>
<authenticationUser username="mcollective" password="marionette" groups="mcollective,everyone"/>
<authenticationUser username="admin" password="OF17WqWx4eKHbV2t8DjsjA==" groups="mcollective,admin,everyone"/>
+ <authenticationUser username="routinginfo" password="routinginfopasswd" groups="routinginfo,everyone"/>
</users>
</simpleAuthenticationPlugin>
<authorizationPlugin>
<map>
<authorizationMap>
<authorizationEntries>
<authorizationEntry queue=">" write="admins" read="admins" admin="admins" />
<authorizationEntry topic=">" write="admins" read="admins" admin="admins" />
<authorizationEntry topic="mcollective.>" write="mcollective" read="mcollective" admin="mcollective" />
<authorizationEntry queue="mcollective.>" write="mcollective" read="mcollective" admin="mcollective" />
+ <authorizationEntry topic="routinginfo.>" write="routinginfo" read="routinginfo" admin="routinginfo" />
+ <authorizationEntry queue="routinginfo.>" write="routinginfo" read="routinginfo" admin="routinginfo" />
<authorizationEntry topic="ActiveMQ.Advisory.>" read="everyone" write="everyone" admin="everyone"/>
</authorizationEntries>
</authorizationMap>
</map>
</authorizationPlugin>
</plugins>
ACTIVEMQ_TOPIC='/topic/routinginfo'
ACTIVEMQ_USERNAME='routinginfo'
ACTIVEMQ_PASSWORD='routinginfopasswd'
ACTIVEMQ_HOST='127.0.0.1'
ACTIVEMQ_PORT='61613'
require 'rubygems'
require 'stomp'
c = Stomp::Client.new("routinginfo", "routinginfopasswd", "localhost", 61613, true)
c.subscribe('/topic/routinginfo') { |msg|
puts
puts msg
}
c.join
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment