라이브러리
[PHP] Stomp::unsubscribe - 기존 구독을 제거합니다.
Stomp::unsubscribe란?
Stomp::unsubscribe는 PHP의 Stomp 라이브러리에 포함된 메서드입니다. 이 메서드는 특정 토픽에 구독한 후에 구독을 해제하는 데 사용됩니다. Stomp는 Simple (or Streaming) Text Oriented Messaging Protocol의 약자로, 메시지를 주고받기 위한 프로토콜입니다.
사용 예제
다음은 Stomp::unsubscribe 메서드를 사용하는 예제입니다.
#hostingforum.kr
php
<?php
// Stomp 라이브러리를 사용하기 위해 require_once를 사용합니다.
require_once 'stomp.php';
// Stomp 객체를 생성합니다.
$stomp = new Stomp('tcp://localhost:61613');
// 토픽에 구독합니다.
$stomp->subscribe('/queue/myQueue');
// 메시지를 받기 위해 반복문을 사용합니다.
while (true) {
$message = $stomp->readFrame();
echo "받은 메시지: $message
";
}
// 토픽에 구독을 해제합니다.
$stomp->unsubscribe('/queue/myQueue');
// Stomp 객체를 닫습니다.
$stomp->disconnect();
?>
Stomp::unsubscribe 메서드의 사용
다음은 Stomp::unsubscribe 메서드를 사용하는 예제입니다.
#hostingforum.kr
php
<?php
// Stomp 라이브러리를 사용하기 위해 require_once를 사용합니다.
require_once 'stomp.php';
// Stomp 객체를 생성합니다.
$stomp = new Stomp('tcp://localhost:61613');
// 토픽에 구독합니다.
$stomp->subscribe('/queue/myQueue');
// 토픽에 구독을 해제합니다.
$stomp->unsubscribe('/queue/myQueue');
// Stomp 객체를 닫습니다.
$stomp->disconnect();
?>
Stomp::unsubscribe 메서드의 파라미터
Stomp::unsubscribe 메서드는 다음과 같은 파라미터를 받습니다.
* `$topic`: 토픽 이름
#hostingforum.kr
php
$stomp->unsubscribe('/queue/myQueue');
Stomp::unsubscribe 메서드의 반환 값
Stomp::unsubscribe 메서드는 다음과 같은 반환 값을 가집니다.
* `bool`: 성공 여부
#hostingforum.kr
php
if ($stomp->unsubscribe('/queue/myQueue')) {
echo "구독 해제 성공
";
} else {
echo "구독 해제 실패
";
}
Stomp::unsubscribe 메서드의 예외
Stomp::unsubscribe 메서드는 다음과 같은 예외를 발생시킬 수 있습니다.
* `StompException`: 토픽이 존재하지 않을 때 발생합니다.
#hostingforum.kr
php
try {
$stomp->unsubscribe('/queue/myQueue');
} catch (StompException $e) {
echo "토픽이 존재하지 않습니다.
";
}
Stomp::unsubscribe 메서드의 참고
Stomp::unsubscribe 메서드는 토픽에 구독한 후에 구독을 해제하는 데 사용됩니다. 이 메서드는 토픽이 존재하지 않을 때 예외를 발생시킬 수 있습니다. 토픽이 존재하지 않을 때는 토픽을 생성한 후에 구독을 해제하거나, 토픽이 존재하지 않아도 구독을 해제할 수 있습니다.
-
- 나우호스팅 @pcs8404
-
호스팅포럼 화이팅!
댓글목록
등록된 댓글이 없습니다.