22
33namespace Enqueue \AmqpExt ;
44
5+ use Interop \Amqp \AmqpConsumer as InteropAmqpConsumer ;
6+ use Interop \Amqp \AmqpMessage as InteropAmqpMessage ;
7+ use Interop \Amqp \AmqpQueue ;
8+ use Interop \Amqp \Impl \AmqpMessage ;
59use Interop \Queue \InvalidMessageException ;
6- use Interop \Queue \PsrConsumer ;
710use Interop \Queue \PsrMessage ;
811
9- class AmqpConsumer implements PsrConsumer
12+ class AmqpConsumer implements InteropAmqpConsumer
1013{
1114 /**
1215 * @var AmqpContext
@@ -38,6 +41,16 @@ class AmqpConsumer implements PsrConsumer
3841 */
3942 private $ receiveMethod ;
4043
44+ /**
45+ * @var int
46+ */
47+ private $ flags ;
48+
49+ /**
50+ * @var string
51+ */
52+ private $ consumerTag ;
53+
4154 /**
4255 * @param AmqpContext $context
4356 * @param AmqpQueue $queue
@@ -50,10 +63,59 @@ public function __construct(AmqpContext $context, AmqpQueue $queue, Buffer $buff
5063 $ this ->context = $ context ;
5164 $ this ->buffer = $ buffer ;
5265 $ this ->receiveMethod = $ receiveMethod ;
66+ $ this ->flags = self ::FLAG_NOPARAM ;
5367
5468 $ this ->isInit = false ;
5569 }
5670
71+ /**
72+ * {@inheritdoc}
73+ */
74+ public function setConsumerTag ($ consumerTag )
75+ {
76+ $ this ->consumerTag = $ consumerTag ;
77+ }
78+
79+ /**
80+ * {@inheritdoc}
81+ */
82+ public function getConsumerTag ()
83+ {
84+ return $ this ->consumerTag ;
85+ }
86+
87+ /**
88+ * {@inheritdoc}
89+ */
90+ public function clearFlags ()
91+ {
92+ $ this ->flags = self ::FLAG_NOPARAM ;
93+ }
94+
95+ /**
96+ * {@inheritdoc}
97+ */
98+ public function addFlag ($ flag )
99+ {
100+ $ this ->flags |= $ flag ;
101+ }
102+
103+ /**
104+ * {@inheritdoc}
105+ */
106+ public function getFlags ()
107+ {
108+ return $ this ->flags ;
109+ }
110+
111+ /**
112+ * {@inheritdoc}
113+ */
114+ public function setFlags ($ flags )
115+ {
116+ $ this ->flags = $ flags ;
117+ }
118+
57119 /**
58120 * {@inheritdoc}
59121 *
@@ -67,7 +129,7 @@ public function getQueue()
67129 /**
68130 * {@inheritdoc}
69131 *
70- * @return AmqpMessage |null
132+ * @return InteropAmqpMessage |null
71133 */
72134 public function receive ($ timeout = 0 )
73135 {
@@ -89,7 +151,7 @@ public function receive($timeout = 0)
89151 */
90152 public function receiveNoWait ()
91153 {
92- if ($ extMessage = $ this ->getExtQueue ()->get ()) {
154+ if ($ extMessage = $ this ->getExtQueue ()->get (Flags :: convertConsumerFlags ( $ this -> flags ) )) {
93155 return $ this ->convertMessage ($ extMessage );
94156 }
95157 }
@@ -101,7 +163,7 @@ public function receiveNoWait()
101163 */
102164 public function acknowledge (PsrMessage $ message )
103165 {
104- InvalidMessageException ::assertMessageInstanceOf ($ message , AmqpMessage ::class);
166+ InvalidMessageException ::assertMessageInstanceOf ($ message , InteropAmqpMessage ::class);
105167
106168 $ this ->getExtQueue ()->ack ($ message ->getDeliveryTag ());
107169 }
@@ -113,7 +175,7 @@ public function acknowledge(PsrMessage $message)
113175 */
114176 public function reject (PsrMessage $ message , $ requeue = false )
115177 {
116- InvalidMessageException ::assertMessageInstanceOf ($ message , AmqpMessage ::class);
178+ InvalidMessageException ::assertMessageInstanceOf ($ message , InteropAmqpMessage ::class);
117179
118180 $ this ->getExtQueue ()->reject (
119181 $ message ->getDeliveryTag (),
@@ -124,7 +186,7 @@ public function reject(PsrMessage $message, $requeue = false)
124186 /**
125187 * @param int $timeout
126188 *
127- * @return AmqpMessage |null
189+ * @return InteropAmqpMessage |null
128190 */
129191 private function receiveBasicGet ($ timeout )
130192 {
@@ -142,7 +204,7 @@ private function receiveBasicGet($timeout)
142204 /**
143205 * @param int $timeout
144206 *
145- * @return AmqpMessage |null
207+ * @return InteropAmqpMessage |null
146208 */
147209 private function receiveBasicConsume ($ timeout )
148210 {
@@ -158,7 +220,7 @@ private function receiveBasicConsume($timeout)
158220 $ extConnection ->setReadTimeout ($ timeout / 1000 );
159221
160222 if (false == $ this ->isInit ) {
161- $ this ->getExtQueue ()->consume (null , AMQP_NOPARAM );
223+ $ this ->getExtQueue ()->consume (null , Flags :: convertConsumerFlags ( $ this -> flags ), $ this -> consumerTag );
162224
163225 $ this ->isInit = true ;
164226 }
@@ -232,7 +294,7 @@ private function getExtQueue()
232294 if (false == $ this ->extQueue ) {
233295 $ extQueue = new \AMQPQueue ($ this ->context ->getExtChannel ());
234296 $ extQueue ->setName ($ this ->queue ->getQueueName ());
235- $ extQueue ->setFlags ($ this ->queue ->getFlags ());
297+ $ extQueue ->setFlags (Flags :: convertQueueFlags ( $ this ->queue ->getFlags () ));
236298 $ extQueue ->setArguments ($ this ->queue ->getArguments ());
237299
238300 $ this ->extQueue = $ extQueue ;
0 commit comments