5
5
namespace PhpMqtt \Client \Contracts ;
6
6
7
7
use DateTime ;
8
- use PhpMqtt \Client \Exceptions \PendingPublishConfirmationAlreadyExistsException ;
9
- use PhpMqtt \Client \PublishedMessage ;
10
- use PhpMqtt \Client \TopicSubscription ;
11
- use PhpMqtt \Client \UnsubscribeRequest ;
8
+ use PhpMqtt \Client \Exceptions \PendingMessageAlreadyExistsException ;
9
+ use PhpMqtt \Client \Exceptions \PendingMessageNotFoundException ;
10
+ use PhpMqtt \Client \Exceptions \RepositoryException ;
11
+ use PhpMqtt \Client \PendingMessage ;
12
+ use PhpMqtt \Client \Subscription ;
12
13
13
14
/**
14
15
* Implementations of this interface provide storage capabilities to an MQTT client.
@@ -31,190 +32,139 @@ interface Repository
31
32
* but it is currently not being used (i.e. in a resend queue).
32
33
*
33
34
* @return int
35
+ * @throws RepositoryException
34
36
*/
35
37
public function newMessageId (): int ;
36
38
37
39
/**
38
- * Releases the given message id, allowing it to be reused in the future.
39
- *
40
- * @param int $messageId
41
- * @return void
42
- */
43
- public function releaseMessageId (int $ messageId ): void ;
44
-
45
- /**
46
- * Returns the number of registered topic subscriptions. The method does
47
- * not differentiate between pending and acknowledged subscriptions.
40
+ * Returns the number of pending outgoing messages.
48
41
*
49
42
* @return int
50
43
*/
51
- public function countTopicSubscriptions (): int ;
52
-
53
- /**
54
- * Adds a topic subscription to the repository.
55
- *
56
- * @param TopicSubscription $subscription
57
- * @return void
58
- */
59
- public function addTopicSubscription (TopicSubscription $ subscription ): void ;
44
+ public function countPendingOutgoingMessages (): int ;
60
45
61
46
/**
62
- * Get all topic subscriptions with the given message identifier.
47
+ * Gets a pending outgoing message with the given message identifier, if found .
63
48
*
64
49
* @param int $messageId
65
- * @return TopicSubscription[]
50
+ * @return PendingMessage|null
66
51
*/
67
- public function getTopicSubscriptionsWithMessageId (int $ messageId ): array ;
52
+ public function getPendingOutgoingMessage (int $ messageId ): ? PendingMessage ;
68
53
69
54
/**
70
- * Find a topic subscription with the given topic .
55
+ * Gets a list of pending outgoing messages last sent before the given date time .
71
56
*
72
- * @param string $topic
73
- * @return TopicSubscription|null
74
- */
75
- public function getTopicSubscriptionByTopic (string $ topic ): ?TopicSubscription ;
76
-
77
- /**
78
- * Get all topic subscriptions matching the given topic.
79
- *
80
- * @param string $topic
81
- * @return TopicSubscription[]
82
- */
83
- public function getTopicSubscriptionsMatchingTopic (string $ topic ): array ;
84
-
85
- /**
86
- * Removes the topic subscription with the given topic from the repository.
87
- * Returns true if a topic subscription existed and has been removed.
88
- * Otherwise, false is returned.
57
+ * If date time is `null`, all pending messages are returned.
89
58
*
90
- * @param string $topic
91
- * @return bool
92
- */
93
- public function removeTopicSubscription (string $ topic ): bool ;
94
-
95
- /**
96
- * Returns the number of pending publish messages.
59
+ * The messages are returned in the same order they were added to the repository.
97
60
*
98
- * @return int
61
+ * @param DateTime|null $dateTime
62
+ * @return PendingMessage[]
99
63
*/
100
- public function countPendingPublishMessages ( ): int ;
64
+ public function getPendingOutgoingMessagesLastSentBefore ( DateTime $ dateTime = null ): array ;
101
65
102
66
/**
103
- * Adds a pending published message to the repository.
67
+ * Adds a pending outgoing message to the repository.
104
68
*
105
- * @param PublishedMessage $message
69
+ * @param PendingMessage $message
106
70
* @return void
71
+ * @throws PendingMessageAlreadyExistsException
107
72
*/
108
- public function addPendingPublishedMessage ( PublishedMessage $ message ): void ;
73
+ public function addPendingOutgoingMessage ( PendingMessage $ message ): void ;
109
74
110
75
/**
111
- * Gets a pending published message with the given message identifier, if found .
76
+ * Marks an existing pending outgoing published message as received in the repository .
112
77
*
113
- * @param int $messageId
114
- * @return PublishedMessage|null
115
- */
116
- public function getPendingPublishedMessageWithMessageId (int $ messageId ): ?PublishedMessage ;
117
-
118
- /**
119
- * Gets a list of pending published messages last sent before the given date time.
120
- *
121
- * @param DateTime $dateTime
122
- * @return PublishedMessage[]
123
- */
124
- public function getPendingPublishedMessagesLastSentBefore (DateTime $ dateTime ): array ;
125
-
126
- /**
127
- * Marks the pending published message with the given message identifier as received.
128
- * If the message has no QoS level of 2, is not found or has already been received,
129
- * false is returned. Otherwise the result will be true.
78
+ * If the message does not exists, an exception is thrown,
79
+ * otherwise `true` is returned if the message was marked as received, and `false`
80
+ * in case it was already marked as received.
130
81
*
131
82
* @param int $messageId
132
83
* @return bool
84
+ * @throws PendingMessageNotFoundException
133
85
*/
134
- public function markPendingPublishedMessageAsReceived (int $ messageId ): bool ;
86
+ public function markPendingOutgoingPublishedMessageAsReceived (int $ messageId ): bool ;
135
87
136
88
/**
137
- * Removes a pending published message from the repository. If a pending message
138
- * with the given identifier is found and successfully removed from the repository,
139
- * `true` is returned. Otherwise `false` will be returned.
89
+ * Removes a pending outgoing message from the repository.
90
+ *
91
+ * If a pending message with the given identifier is found and
92
+ * successfully removed from the repository, `true` is returned.
93
+ * Otherwise `false` will be returned.
140
94
*
141
95
* @param int $messageId
142
96
* @return bool
143
97
*/
144
- public function removePendingPublishedMessage (int $ messageId ): bool ;
98
+ public function removePendingOutgoingMessage (int $ messageId ): bool ;
145
99
146
100
/**
147
- * Returns the number of pending unsubscribe requests .
101
+ * Returns the number of pending incoming messages .
148
102
*
149
103
* @return int
150
104
*/
151
- public function countPendingUnsubscribeRequests (): int ;
105
+ public function countPendingIncomingMessages (): int ;
152
106
153
107
/**
154
- * Adds a pending unsubscribe request to the repository.
155
- *
156
- * @param UnsubscribeRequest $request
157
- * @return void
158
- */
159
- public function addPendingUnsubscribeRequest (UnsubscribeRequest $ request ): void ;
160
-
161
- /**
162
- * Gets a pending unsubscribe request with the given message identifier, if found.
108
+ * Gets a pending incoming message with the given message identifier, if found.
163
109
*
164
110
* @param int $messageId
165
- * @return UnsubscribeRequest |null
111
+ * @return PendingMessage |null
166
112
*/
167
- public function getPendingUnsubscribeRequestWithMessageId (int $ messageId ): ?UnsubscribeRequest ;
113
+ public function getPendingIncomingMessage (int $ messageId ): ?PendingMessage ;
168
114
169
115
/**
170
- * Gets a list of pending unsubscribe requests last sent before the given date time .
116
+ * Adds a pending outgoing message to the repository .
171
117
*
172
- * @param DateTime $dateTime
173
- * @return UnsubscribeRequest[]
118
+ * @param PendingMessage $message
119
+ * @return void
120
+ * @throws PendingMessageAlreadyExistsException
174
121
*/
175
- public function getPendingUnsubscribeRequestsLastSentBefore ( DateTime $ dateTime ): array ;
122
+ public function addPendingIncomingMessage ( PendingMessage $ message ): void ;
176
123
177
124
/**
178
- * Removes a pending unsubscribe requests from the repository. If a pending request
179
- * with the given identifier is found and successfully removed from the repository,
180
- * `true` is returned. Otherwise `false` will be returned.
125
+ * Removes a pending incoming message from the repository.
126
+ *
127
+ * If a pending message with the given identifier is found and
128
+ * successfully removed from the repository, `true` is returned.
129
+ * Otherwise `false` will be returned.
181
130
*
182
131
* @param int $messageId
183
132
* @return bool
184
133
*/
185
- public function removePendingUnsubscribeRequest (int $ messageId ): bool ;
134
+ public function removePendingIncomingMessage (int $ messageId ): bool ;
186
135
187
136
/**
188
- * Returns the number of pending publish confirmations .
137
+ * Returns the number of registered subscriptions .
189
138
*
190
139
* @return int
191
140
*/
192
- public function countPendingPublishConfirmations (): int ;
141
+ public function countSubscriptions (): int ;
193
142
194
143
/**
195
- * Adds a pending publish confirmation to the repository.
144
+ * Adds a subscription to the repository.
196
145
*
197
- * @param PublishedMessage $message
146
+ * @param Subscription $subscription
198
147
* @return void
199
- * @throws PendingPublishConfirmationAlreadyExistsException
200
148
*/
201
- public function addPendingPublishConfirmation ( PublishedMessage $ message ): void ;
149
+ public function addSubscription ( Subscription $ subscription ): void ;
202
150
203
151
/**
204
- * Gets a pending publish confirmation with the given message identifier, if found .
152
+ * Gets all subscriptions matching the given criteria .
205
153
*
206
- * @param int $messageId
207
- * @return PublishedMessage|null
154
+ * @param string|null $topicName
155
+ * @param int|null $subscriptionId
156
+ * @return Subscription[]
208
157
*/
209
- public function getPendingPublishConfirmationWithMessageId ( int $ messageId ): ? PublishedMessage ;
158
+ public function getMatchingSubscriptions ( string $ topicName = null , int $ subscriptionId = null ): array ;
210
159
211
160
/**
212
- * Removes the pending publish confirmation with the given message identifier
213
- * from the repository. This is normally done as soon as a transaction has been
214
- * successfully finished by the publisher.
161
+ * Removes the subscription with the given topic filter from the repository.
215
162
*
216
- * @param int $messageId
163
+ * Returns `true` if a topic subscription existed and has been removed.
164
+ * Otherwise, `false` is returned.
165
+ *
166
+ * @param string $topicFilter
217
167
* @return bool
218
168
*/
219
- public function removePendingPublishConfirmation ( int $ messageId ): bool ;
169
+ public function removeSubscription ( string $ topicFilter ): bool ;
220
170
}
0 commit comments