-
-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathSimpleStomp.php
More file actions
162 lines (148 loc) · 3.84 KB
/
Copy pathSimpleStomp.php
File metadata and controls
162 lines (148 loc) · 3.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php
/*
* This file is part of the Stomp package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Stomp;
use Stomp\Exception\StompException;
use Stomp\Protocol\Protocol;
use Stomp\Transport\Frame;
use Stomp\Transport\Message;
/**
* Simple Stomp Client
*
* This is a legacy implementation of the old Stomp Client (Version 2-3).
* It's an almost stateless client, only wrapping some protocol calls for you.
*
* @package Stomp
* @author Jens Radtke <swefl.oss@fin-sn.de>
*/
class SimpleStomp
{
/**
* @var Client
*/
protected $client;
/**
* LegacyStomp constructor.
*
* @param Client $client
*/
public function __construct(Client $client)
{
$this->client = $client;
}
/**
* Read response frame from server
*
* @return Frame|false when no frame to read
*/
public function read()
{
return $this->client->readFrame();
}
/**
* Register to listen to a given destination
*
* @param string $destination Destination queue
* @param null $subscriptionId
* @param string $ack
* @param string $selector
* @param array $header
* @return bool
*/
public function subscribe($destination, $subscriptionId = null, $ack = 'auto', $selector = null, array $header = [])
{
return $this->client->sendFrame(
$this->getProtocol()->getSubscribeFrame($destination, $subscriptionId, $ack, $selector)->addHeaders($header)
);
}
/**
* @return Protocol
*/
protected function getProtocol()
{
return $this->client->getProtocol();
}
/**
* Send a message
*
* @param string $destination
* @param Message $message
* @return bool
* @throws StompException
*/
public function send($destination, Message $message)
{
return $this->client->send($destination, $message);
}
/**
* Remove an existing subscription
*
* @param string $destination
* @param string $subscriptionId
* @param array $header
* @return boolean
* @throws StompException
*/
public function unsubscribe($destination, $subscriptionId = null, array $header = [])
{
return $this->client->sendFrame(
$this->getProtocol()->getUnsubscribeFrame($destination, $subscriptionId)->addHeaders($header)
);
}
/**
* Start a transaction
*
* @param string $transactionId
* @return boolean
* @throws StompException
*/
public function begin($transactionId = null)
{
return $this->client->sendFrame($this->getProtocol()->getBeginFrame($transactionId));
}
/**
* Commit a transaction in progress
*
* @param string $transactionId
* @return boolean
* @throws StompException
*/
public function commit($transactionId = null)
{
return $this->client->sendFrame($this->getProtocol()->getCommitFrame($transactionId));
}
/**
* Roll back a transaction in progress
*
* @param string $transactionId
* @return bool
*/
public function abort($transactionId = null)
{
return $this->client->sendFrame($this->getProtocol()->getAbortFrame($transactionId));
}
/**
* Acknowledge consumption of a message from a subscription
*
* @param Frame $frame
* @return void
*/
public function ack(Frame $frame)
{
$this->client->sendFrame($this->getProtocol()->getAckFrame($frame), false);
}
/**
* Not acknowledge consumption of a message from a subscription
*
* @param Frame $frame
* @return void
*/
public function nack(Frame $frame)
{
$this->client->sendFrame($this->getProtocol()->getNackFrame($frame), false);
}
}