php activemq

array(						//ActiveMQ 参数			
			'destination' => '/queue/test',//监听ID
			'active_usr' => 'guest',
			'active_psw' => 'password',
			'stomp_uri' => 'tcp://192.168.10.189:61613',
			),
		);
	$result = array(
	"message"=>array(
		"username"=>"消息发送人用户名1",
		"pushtime"=>"消息发送时间",
		"pushjob"=>"消息发送人身份",
		"getonname"=>"消息发送人上车地点",
		"getoutname"=>"消息发送人下车地点",
		"comeid"=>"消息发送人uid",
		"getid"=>"接收消息人uid",
		"type"=>"消息类型(确认拼1,取消消息2)",
		"carpooled"=>"行程id",
		"poolmsgid"=>"消息发送人拼车信息id",
		"pooledmsgid"=>"接收消息人拼车信息id",

	)
	); 
	
	$detail = json_encode($result);
	try {
		$stomp = new Stomp($config['active']['stomp_uri']);//uri
		$stomp->connect($config['active']['active_usr'], $config['active']['active_psw'],array('persistent'=>'true'));
		$row = $stomp->send($config['active']['destination'],$detail);
		if($row){
			$status = 0; $res = '数据发送成功';
		}else{
			$status = 104;   $res = '数据发送失败';
		}
		print $res;
	} catch(StompException $e) {
		
			$result = array('status'=>103,'res'=>$e->getMessage());
			print_r(json_encode($result));
			exit();
		
		
	}


rective.php

connect("guest", "password");

// set read timeout
$con->setReadTimeout(1);

// subscribe to the queue
$con->subscribe("/queue/test");//, array("transformation" => "jms-map-json")

// receive a message from the queue
$msg = $con->readFrame();

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

// disconnect
$con->disconnect();

配置:

activemq.xml





    
    
        
            file:${activemq.conf}/credentials.properties
        
    

    
    

        

        
            
              
                
                    
                  
                    
                  
                
                
                  
                
              
            
        


        
        
            
        

        
       
            
        
	

          
          
            
                
                    
                
                
                    
                
                
                    
                
            
        

        
        
            

	  
            
        

        
        
            
        

    

    
    





你可能感兴趣的:(php,ActiveMQ)