<broker xmlns = "activemq.apache.org/schema/core" brokerName = "localhost" dataDirectory = "${activemq.base}/data" destroyApplicationContextOnStop = "true" persistent = "true" useShutdownHook = "false" >
<broker xmlns = "activemq.apache.org/schema/core" brokerName = "localhost" dataDirectory = "${activemq.base}/data" destroyApplicationContextOnStop = "true" persistent = "true" useShutdownHook = "false" >
<persistenceAdapter > <br/>
<jdbcPersistenceAdapter dataSource = "#mysql-ds" /> <br/>
</persistenceAdapter > <br/>
<br/>
<bean id = "mysql-ds" class = "org.apache.commons.dbcp.BasicDataSource" destroy-method = "close" > <br/>
<property name = "driverClassName" value = "com.mysql.jdbc.Driver" /> <br/>
<property name = "url" value = "jdbc:mysql://localhost/activemq?relaxAutoCommit=true" /> <br/>
<property name = "username" value = "activemq" /> <br/>
<property name = "password" value = "activemq" /> <br/>
<property name = "poolPreparedStatements" value = "true" /> <br/>
</bean >
<transportConnectors > <br/>
<transportConnector name = "openwire" uri = "tcp://0.0.0.0:61616" /> <br/>
<transportConnector name = "openwire2" uri = "stomp://0.0.0.0:61613" /> <br/>
</transportConnectors >
Here I asked 2 different connections for different protocols, this is due to the fact that I use the STOMP library to connect to PHP, and under Delphi I managed to find a component that works steadily over TCP.
<plugins > <br/>
<jaasAuthenticationPlugin configuration = "activemq-domain" /> <br/>
<authorizationPlugin > <br/>
<map > <br/>
<authorizationMap > <br/>
<authorizationEntries > <br/>
<authorizationEntry queue = ">" read = "admins" write = "admins" admin = "admins" /> <br/>
<authorizationEntry queue = "icq.>" read = "users" write = "users" admin = "admins" /> <br/>
<authorizationEntry topic = "ActiveMQ.Advisory.>" read = "guests,users" write = "guests,users" admin = "guests,users" /> <br/>
</authorizationEntries > <br/>
</authorizationMap > <br/>
</map > <br/>
</authorizationPlugin > <br/>
</plugins >
admins=system,sslclient,client,broker1,broker2
users=icq
guests=guest
system=password
icq=secret
You will also need a login.config file, it is easier to download it entirely and drop it into the / conf folder. After all the settings, restart the service and go to the address http: // localhost: 8161 / admin / , if everything is done correctly, you will be met by the control panel, if so, go to Queues and create a queue called icq.
<?php <br/>
require_once 'Stomp.php' ; <br/>
$c = new StompConnection ( "localhost" ) ; <br/>
$result = $c -> connect ( "icq" , "bot" ) ; <br/>
<br/>
$mess = '<?xml version="1.0" encoding="windows-1251"?><br/>
<reference><br/>
<type>send</type><br/>
<to>111111111</to><br/>
<from>Test send:</from><br/>
<mes> message</mes><br/>
</reference>' ; <br/>
<br/>
$mess = iconv ( 'cp1251' , 'UTF-8' , $mess ) ; <br/>
$c -> send ( "/queue/icq" , $mess , array ( 'persistent' => 'true' ) ) ; <br/>
$c -> disconnect ( ) ; <br/>
?>
I had to mess around with encodings for quite a while so that I could send messages with Russian text, so don’t be surprised when you see cascading conversions to different encodings in scripts, otherwise it didn’t want to work. After calling send.php, a message will be sent to the specified UIN and this fact will also be reflected in the logs.
<?php <br/>
ini_set ( 'display_errors' , 0 ) ; <br/>
error_reporting ( 2 ) ; <br/>
<br/>
if ( $send_report ) { <br/>
include_once ( "Stomp.php" ) ; <br/>
<br/>
function send_report ( $message , $to = '1212312' , $from = 'SENDER' ) { <br/>
global $send_report , $stomp_server , $stomp_url , $stomp_user , $stomp_psw ; <br/>
if ( ! $send_report ) return false ; <br/>
$c = new StompConnection ( $stomp_server ) ; <br/>
$result = $c -> connect ( $stomp_user , $stomp_psw ) ; <br/>
if ( ! is_array ( $to ) ) $to = array ( $to ) ; <br/>
foreach ( $to as $i ) { <br/>
$mess = '<?xml version="1.0" encoding="windows-1251"?><br/>
<reference><br/>
<type>send</type><br/>
<to>' . $i . '</to><br/>
<from>' . $from . '</from><br/>
<mes>' . $message . '</mes><br/>
</reference>' ; <br/>
$c -> send ( $stomp_url , iconv ( 'cp1251' , 'UTF-8' , $mess ) , array ( 'persistent' => 'true' ) ) ; <br/>
} <br/>
$c -> disconnect ( ) ; <br/>
} <br/>
} <br/>
<br/>
function user_log ( $errno , $errmsg , $file , $line ) { <br/>
global $send_report ; <br/>
if ( $errno == 2 ) { <br/>
$filename = strftime ( '%d.%m.%Y %H-%M-%S_' ) . $_REQUEST [ 'PHPSESSID' ] . '.err' ; <br/>
$fl = fopen ( 'errors/' . $filename , 'w' ) ; <br/>
$_SESSION [ 'ERROR_TEXT' ] = 'WARNING: ' . $errmsg . ' in ' . $file . ' on line ' . $line ; <br/>
$_SESSION [ 'ERROR_TIME' ] = strftime ( '%d.%m.%Y %H-%M-%S' ) ; <br/>
$_SESSION [ 'ERROR_PHPSESSID' ] = $_REQUEST [ 'PHPSESSID' ] ; <br/>
$_SESSION [ 'ERROR_TYPE' ] = 'PHP SCRIPT ERROR' ; <br/>
fwrite ( $fl , serialize ( $_SESSION ) ) ; <br/>
fclose ( $fl ) ; <br/>
if ( $send_report ) send_report ( $_SESSION [ 'ERROR_TEXT' ] ) ; <br/>
} <br/>
} <br/>
<br/>
set_error_handler ( 'user_log' ) ; <br/>
?>
For understandable causal reasons, I crypt the entire contents of these reports, which I advise everyone to do.
Source: https://habr.com/ru/post/116038/