Skip to content

Commit

Permalink
moving php stomp client to github
Browse files Browse the repository at this point in the history
  • Loading branch information
dejanb committed Aug 4, 2011
0 parents commit c7e12bf
Show file tree
Hide file tree
Showing 21 changed files with 2,173 additions and 0 deletions.
14 changes: 14 additions & 0 deletions README.txt
@@ -0,0 +1,14 @@
Installing

Obtain the source of the library by downloading the distribution and add its content to your `include_path`. Alternatively, you can grab the source and add `src/main` folder to your `include_path`.

Running Examples

Examples are located in src/examples folder. Before running them, be sure you have installed this library properly and you have started ActiveMQ broker (recommended version 5.3.0) with Stomp connector enabled (http://activemq.apache.org/stomp.html).

You can start by running

cd examples
php first.php

Also, be sure to check comments in the particular examples for some special configuration steps (if needed).
20 changes: 20 additions & 0 deletions build.xml
@@ -0,0 +1,20 @@
<?xml version="1.0"?>

<project name="stomp-cli" basedir="." default="deploy">

<target name="clean" description="--> Clean output directories">
<delete dir="target"/>
</target>

<target name="deploy" depends="clean" description="--> Deploy library">
<mkdir dir="target"/>
<tar destfile="target/stomp-php-1.1-SNAPSHOT.tar.gz" compression="gzip">
<fileset dir="src/main/">
<include name="**/*"/>
</fileset>
<tarfileset dir="src/examples" prefix="examples">
<include name="**/*"/>
</tarfileset>
</tar>
</target>
</project>
35 changes: 35 additions & 0 deletions src/examples/activemq-connectivity.xml
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2009 Progress Software, Inc. All rights reserved.
http://fusesource.com
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<beans>
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>

<broker useJmx="false" persistent="false" xmlns="http://activemq.apache.org/schema/core" populateJMSXUserID="true">

<transportConnectors>
<transportConnector name="stomp+ssl" uri="stomp+ssl://localhost:61612"/>
</transportConnectors>

<sslContext>
<sslContext keyStore="file:${activemq.base}/conf/broker.ks"
keyStorePassword="password" trustStore="file:${activemq.base}/conf/broker.ts"
trustStorePassword="password"/>
</sslContext>

</broker>

</beans>
84 changes: 84 additions & 0 deletions src/examples/activemq-security.xml
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!--
Secure ActiveMQ broker
For more information, see:
http://activemq.apache.org/security.html
To run ActiveMQ with this configuration add xbean:conf/activemq-security.xml to your command
e.g. $ bin/activemq xbean:conf/activemq-security.xml
-->
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:amq="http://activemq.apache.org/schema/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<value>file:${activemq.base}/conf/credentials.properties</value>
</property>
</bean>

<broker useJmx="true" persistent="false" xmlns="http://activemq.apache.org/schema/core">

<plugins>
<!-- Configure authentication; Username, passwords and groups -->
<simpleAuthenticationPlugin>
<users>
<authenticationUser username="system" password="manager"
groups="users,admins"/>
<authenticationUser username="user" password="password"
groups="users"/>
<authenticationUser username="guest" password="password" groups="guests"/>
</users>
</simpleAuthenticationPlugin>


<!-- Lets configure a destination based authorization mechanism -->
<authorizationPlugin>
<map>
<authorizationMap>
<authorizationEntries>
<authorizationEntry queue=">" read="admins" write="admins" admin="admins" />
<authorizationEntry queue="USERS.>" read="users" write="users" admin="users" />
<authorizationEntry queue="GUEST.>" read="guests" write="guests,users" admin="guests,users" />

<authorizationEntry queue="TEST.Q" read="guests" write="guests" />

<authorizationEntry topic=">" read="admins" write="admins" admin="admins" />
<authorizationEntry topic="USERS.>" read="users" write="users" admin="users" />
<authorizationEntry topic="GUEST.>" read="guests" write="guests,users" admin="guests,users" />

<authorizationEntry topic="ActiveMQ.Advisory.>" read="guests,users" write="guests,users" admin="guests,users"/>
</authorizationEntries>
</authorizationMap>
</map>
</authorizationPlugin>
</plugins>

<transportConnectors>
<transportConnector name="default" uri="stomp://0.0.0.0:61613"/>
</transportConnectors>

</broker>

</beans>
49 changes: 49 additions & 0 deletions src/examples/binary.php
@@ -0,0 +1,49 @@
<?php
/**
*
* Copyright (C) 2009 Progress Software, Inc. All rights reserved.
* http://fusesource.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// include a library
require_once("Stomp.php");
require_once("Stomp/Message/Bytes.php");
// make a connection
$con = new Stomp("tcp://localhost:61613");
// connect
$con->connect();
// send a message to the queue
$body = "test";
$bytesMessage = new StompMessageBytes($body);
$con->send("/queue/test", $bytesMessage);
echo "Sending message: ";
print_r($body . "\n");

$con->subscribe("/queue/test");
$msg = $con->readFrame();

// extract
if ( $msg != null) {
echo "Received message: ";
print_r($msg->body . "\n");
// mark the message as received in the queue
$con->ack($msg);
} else {
echo "Failed to receive a message\n";
}

// disconnect
$con->disconnect();
?>
51 changes: 51 additions & 0 deletions src/examples/connectivity.php
@@ -0,0 +1,51 @@
<?php
/**
*
* Copyright (C) 2009 Progress Software, Inc. All rights reserved.
* http://fusesource.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
To successfully run this example, you must first start the broker with stomp+ssl enabled.
You can do that by executing:
$ ${ACTIVEMQ_HOME}/bin/activemq xbean:activemq-connectivity.xml
Then you can execute this example with:
$ php connectivity.php
*/
// include a library
require_once("Stomp.php");
// make a connection
$con = new Stomp("failover://(tcp://localhost:61614,ssl://localhost:61612)?randomize=false");
// connect
$con->connect();
// send a message to the queue
$con->send("/queue/test", "test");
echo "Sent message with body 'test'\n";
// subscribe to the queue
$con->subscribe("/queue/test");
// receive a message from the queue
$msg = $con->readFrame();

// do what you want with the message
if ( $msg != null) {
echo "Received message with body '$msg->body'\n";
// mark the message as received in the queue
$con->ack($msg);
} else {
echo "Failed to receive a message\n";
}

// disconnect
$con->disconnect();
?>
89 changes: 89 additions & 0 deletions src/examples/durable.php
@@ -0,0 +1,89 @@
<?php
/**
*
* Copyright (C) 2009 Progress Software, Inc. All rights reserved.
* http://fusesource.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// include a library
require_once("Stomp.php");

// create a producer
$producer = new Stomp("tcp://localhost:61613");
// create a consumer
$consumer = new Stomp("tcp://localhost:61613");
$consumer->setReadTimeout(1);
// set clientId on a consumer to make it durable
$consumer->clientId = "test";
// connect
$producer->connect();
$consumer->connect();
// subscribe to the topic
$consumer->subscribe("/topic/test");

sleep(1);

// send a message to the topic
$producer->send("/topic/test", "test", array('persistent'=>'true'));
echo "Message 'test' sent to topic\n";

// receive a message from the topic
$msg = $consumer->readFrame();

// do what you want with the message
if ( $msg != null) {
echo "Message '$msg->body' received from topic\n";
$consumer->ack($msg);
} else {
echo "Failed to receive a message\n";
}

sleep(1);

// disconnect durable consumer
$consumer->unsubscribe("/topic/test");
$consumer->disconnect();
echo "Disconnecting consumer\n";

// send a message while consumer is disconnected
// note: only persistent messages will be redelivered to the durable consumer
$producer->send("/topic/test", "test1", array('persistent'=>'true'));
echo "Message 'test1' sent to topic\n";


// reconnect the durable consumer
$consumer = new Stomp("tcp://localhost:61613");
$consumer->clientId = "test";
$consumer->connect();
$consumer->subscribe("/topic/test");
echo "Reconnecting consumer\n";

// receive a message from the topic
$msg = $consumer->readFrame();

// do what you want with the message
if ( $msg != null) {
echo "Message '$msg->body' received from topic\n";
$consumer->ack($msg);
} else {
echo "Failed to receive a message\n";
}

// disconnect
$consumer->unsubscribe("/topic/test");
$consumer->disconnect();
$producer->disconnect();

?>

0 comments on commit c7e12bf

Please sign in to comment.