Skip to content

Instantly share code, notes, and snippets.

@marinsagovac
Created March 28, 2018 14:52
Show Gist options
  • Save marinsagovac/444fbfe985e25591c548782186539830 to your computer and use it in GitHub Desktop.
Save marinsagovac/444fbfe985e25591c548782186539830 to your computer and use it in GitHub Desktop.
ActiveMQ Docs + Symfony
ActiveMQ
********
# Github: https://github.com/stomp-php/stomp-php
composer require grimkirill/stomp
# Apache ActiveMNQ
# Requirements: JRE 1.7
# JAVA_HOME env set
Default port: 61616
# Download
Latest stable: http://activemq.apache.org/download.html
Get form repos: http://www.apache.org/dyn/closer.cgi?filename=/activemq/5.15.3/apache-activemq-5.15.3-bin.tar.gz&action=download
sudo mkdir -p /opt/activemq
cd /opt/activemq
wget http://www-eu.apache.org/dist/activemq/5.15.3/apache-activemq-5.15.3-bin.tar.gz
# Download stuff:
http://www-eu.apache.org/dist/activemq/
tar -xf apache-activemq-5.15.3-bin.tar.gz
mv apache-activemq-5.15.3 mq
# Starting ActiveMQ
bin/activemq start
# You got:
INFO: Loading '/opt/activemq/mq//bin/env'
INFO: Using java '/usr/lib/jvm/java-8-oracle/bin/java'
INFO: Starting - inspect logfiles specified in logging.properties and log4j.properties to get details
INFO: pidfile created : '/opt/activemq/mq//data/activemq.pid' (pid '17312')
# Run as foreground:
./bin/activemq console
# Run as daemon process:
./bin/activemq start
# Stop service:
./bin/activemq stop
# Admin panel
http://127.0.0.1:8161/admin/
user: admin
pass: admin
To change users: conf/jetty-real.properties
# Defines users that can access the web (console, demo, etc.)
# username: password [,rolename ...]
admin: admin, admin
user: user, user
# Create queue name
Navigate to queues: http://127.0.0.1:8161/admin/queues.jsp
Add queue name and click Create
Send test message using "Send to"
# Command shell
./activemq console
# Check port
netstat -nl | grep 61616
# Monitoring services web console
http://rhq-project.github.io/rhq/
# Example message brokers
http://activemq.apache.org/examples.html
https://github.com/stomp-php/stomp-php/wiki/First-example
**************************************************************
<?php
namespace SMSme\API\SMS\Action;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Stomp\Client;
use DateTime;
class Activemq
{
/**
*
* @Route("/api/mqclient")
*/
public function client(Request $request)
{
$client = new \Stomp\Client(array('tcp://127.0.0.1:61613'), array(
'login' => 'admin',
'passcode' => 'admin',
'host' => '/',
'queue_prefix' => '/queue/',
));
for ($i=0; $i<255; $i++) {
$client->send('smsme', 'hello message');
}
// $client->subscribe('smsme');
// while ($message = $client->readMessage()) {
// echo $message->getBody();
// $message->ack();
// }
exit;
}
/**
* @Route("/api/mqsrv")
*/
public function server(Request $request)
{
$client = new \Stomp\Client('tcp://127.0.0.1:61613', array('login' => 'admin', 'passcode' => 'admin'));
$consumer = new \Stomp\Helper\Consumer($client, '/queue/smsme');
$endTime = new \DateTime('+30 second');
$condition = function () use ($endTime) {
return ((new DateTime()) < $endTime);
};
$consumer->run(function($data, $headers) {
var_dump($data);
print_r($headers);
return date('c');
}, $condition);
exit;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment