現在、xbean を使用して ActiveMQ を開始できますが、起動時に ActiveMQ が UNIX サービスとして開始されません。
/home/username/activemq/bin/activemq start xbean:/home/username/activemq/conf/my-activemq.xml
コンソールからセットアップを実行するように求められたので、
/home/username/activemq/bin/activemq setup etc/default/activemq
xbean を使用している場合、コンソールが構成ファイルを作成するように指示する理由がわかりません
次に、producer.php と consumer.php を作成しました。
cd /etc/init.d/
cat > producer.php
<?php
$queue1 = '/queue/queue1';
try {$stomp = new Stomp('tcp://localhost:61613');}
catch(StompException $e) {die('Connection failed: ' . $e->getMessage());}
for($i=1;$i<10;$i++){$msg1 = "queue one my data".$i;
$stomp->send($queue1, $msg1, array('persistent' => 'true'));}
unset($stomp);
?>
cat > consumer.php
<?php
$queue1 = '/queue/queue1';
try {$stomp = new Stomp('tcp://localhost:61613');}
catch(StompException $e) {die('Connection failed: ' . $e->getMessage());}
$stomp->subscribe($queue1);
while(1){$frame = $stomp->readFrame();
if ( $frame != null) {echo $frame->body; //process your message
echo "\n";
$stomp->ack($frame);}} unset($stomp);
?>
nohupでconsumer.phpを起動
nohup php consumer.php > consumer.log 2>&1 &
これをコンソールに返しました
[1] 32707
作成された起動ファイル
cat > activemqstart.sh
#!/bin/bash
export JAVA_HOME=/usr
/usr/share/php/activemq/bin/activemq &
停止ファイルを作成しました
cat > activemqstop.sh
#!/bin/bash
export JAVA_HOME=/usr
/usr/share/php/activemq/bin/activemq-admin stop
サービス構成スクリプト
cat > activemq
#!/bin/bash
#
# activemq Starts ActiveMQ.
#
# chkconfig: 345 88 12
# description: ActiveMQ is a JMS Messaging Queue Server.
### BEGIN INIT INFO
# Provides: $activemq
### END INIT INFO
# Source function library.
. /etc/init.d/functions
[ -f /etc/init.d/activemqstart.sh ] || exit 0
[ -f /etc/init.d/activemqstop.sh ] || exit 0
RETVAL=0
umask 077
start() {
echo -n $"Starting ActiveMQ: "
daemon /etc/init.d/activemqstart.sh
echo
return $RETVAL
}
stop() {
echo -n $"Shutting down ActiveMQ: "
daemon su -c /etc/init.d/activemqstop.sh activemq
echo
return $RETVAL
}
restart() {
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
restart
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
esac
exit $?
次に、権限を設定します
chmod +x /etc/init.d/activemqstart.sh
chmod +x /etc/init.d/activemqstop.sh
chmod +x /etc/init.d/activemq
/sbin/chkconfig --add activemq
/sbin/chkconfig activemq on
actviemq.logをクリアしました
cat /dev/null > /home/username/activemq/data/activemq.log
再起動した
reboot
ログを確認しましたが、空であり、ActiveMQ は実行されていません
more /home/username/activemq/data/activemq.log