Stomp Client Stomp::ack
stomp_ack
(PECL stomp >= 0.1.0)
Stomp::ack -- stomp_ack — 메시지 소비 확인
설명
객체 지향 스타일(메소드):
public Stomp::ack(mixed $msg
, array $headers
= ?): bool
절차 스타일:
stomp_ack(resource $link
, mixed $msg
, array $headers
= ?): bool
클라이언트 승인을 사용하여 구독의 메시지 소비를 승인합니다.
매개변수
link
- 절차 스타일만 해당: stomp_connect()에 의해 반환된 stomp 링크 식별자입니다.
msg
- 확인할 메시지/messageId입니다.
headers
- 추가 헤더를 포함하는 연관 배열(예: receipt).
반환 값
성공하면 true
를, 실패하면 false
를 반환합니다.
Examples
예제 #1 객체 지향 스타일
<?php
$queue = '/queue/foo';
$msg = 'bar';
/* connection */
try {
$stomp = new Stomp('tcp://localhost:61613');
} catch(StompException $e) {
die('Connection failed: ' . $e->getMessage());
}
/* send a message to the queue 'foo' */
$stomp->send($queue, $msg);
/* subscribe to messages from the queue 'foo' */
$stomp->subscribe($queue);
/* read a frame */
$frame = $stomp->readFrame();
if ($frame->body === $msg) {
/* acknowledge that the frame was received */
$stomp->ack($frame);
}
/* remove the subscription */
$stomp->unsubscribe($queue);
/* close connection */
unset($stomp);
?>
예제 #2 절차적 스타일
<?php
$queue = '/queue/foo';
$msg = 'bar';
/* connection */
$link = stomp_connect('ssl://localhost:61612');
/* check connection */
if (!$link) {
die('Connection failed: ' . stomp_connect_error());
}
/* begin a transaction */
stomp_begin($link, 't1');
/* send a message to the queue 'foo' */
stomp_send($link, $queue, $msg, array('transaction' => 't1'));
/* commit a transaction */
stomp_commit($link, 't1');
/* subscribe to messages from the queue 'foo' */
stomp_subscribe($link, $queue);
/* read a frame */
$frame = stomp_read_frame($link);
if ($frame['body'] === $msg) {
/* acknowledge that the frame was received */
stomp_ack($link, $frame['headers']['message-id']);
}
/* remove the subscription */
stomp_unsubscribe($link, $queue);
/* close connection */
stomp_close($link);
?>
메모
메모: 메시지 승인이 명명된 트랜잭션의 일부여야 함을 나타내는 트랜잭션 헤더가 지정될 수 있습니다.
팁 Stomp는 본질적으로 비동기식입니다. receipt 헤더를 추가하여 동기 통신을 구현할 수 있습니다. 이렇게 하면 서버가 메시지 수신을 확인하거나 읽기 제한 시간에 도달할 때까지 메서드가 아무 것도 반환하지 않습니다.