File tree Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ class RpcClient extends BaseAmqp
10
10
protected $ replies = array ();
11
11
protected $ expectSerializedResponse ;
12
12
protected $ timeout = 0 ;
13
+ protected $ notifyCallback ;
13
14
14
15
private $ queueName ;
15
16
private $ unserializer = 'unserialize ' ;
@@ -80,6 +81,9 @@ public function processMessage(AMQPMessage $msg)
80
81
if ($ this ->expectSerializedResponse ) {
81
82
$ messageBody = call_user_func ($ this ->unserializer , $ messageBody );
82
83
}
84
+ if ($ this ->notifyCallback !== null ) {
85
+ call_user_func ($ this ->notifyCallback , $ messageBody );
86
+ }
83
87
84
88
$ this ->replies [$ msg ->get ('correlation_id ' )] = $ messageBody ;
85
89
}
@@ -98,6 +102,15 @@ public function setUnserializer($unserializer)
98
102
$ this ->unserializer = $ unserializer ;
99
103
}
100
104
105
+ public function notify ($ callback )
106
+ {
107
+ if (is_callable ($ callback )) {
108
+ $ this ->notifyCallback = $ callback ;
109
+ } else {
110
+ throw new \InvalidArgumentException ('First parameter expects to be callable ' );
111
+ }
112
+ }
113
+
101
114
public function setDirectReplyTo ($ directReplyTo )
102
115
{
103
116
$ this ->directReplyTo = $ directReplyTo ;
Original file line number Diff line number Diff line change @@ -22,4 +22,38 @@ public function testProcessMessageWithCustomUnserializer()
22
22
});
23
23
$ client ->processMessage ($ message );
24
24
}
25
+
26
+ public function testProcessMessageWithNotifyMethod ()
27
+ {
28
+ /** @var RpcClient $client */
29
+ $ client = $ this ->getMockBuilder ('\OldSound\RabbitMqBundle\RabbitMq\RpcClient ' )
30
+ ->setMethods (array ('sendReply ' , 'maybeStopConsumer ' ))
31
+ ->disableOriginalConstructor ()
32
+ ->getMock ();
33
+ $ expectedNotify = 'message ' ;
34
+ $ message = $ this ->getMock ('\PhpAmqpLib\Message\AMQPMessage ' , array ('get ' ), array ($ expectedNotify ));
35
+ $ notified = false ;
36
+ $ client ->notify (function ($ message ) use (&$ notified ) {
37
+ $ notified = $ message ;
38
+ });
39
+
40
+ $ client ->initClient (false );
41
+ $ client ->processMessage ($ message );
42
+
43
+ $ this ->assertSame ($ expectedNotify , $ notified );
44
+ }
45
+
46
+ /**
47
+ * @expectedException \InvalidArgumentException
48
+ */
49
+ public function testInvalidParameterOnNotify ()
50
+ {
51
+ /** @var RpcClient $client */
52
+ $ client = $ this ->getMockBuilder ('\OldSound\RabbitMqBundle\RabbitMq\RpcClient ' )
53
+ ->setMethods (array ('sendReply ' , 'maybeStopConsumer ' ))
54
+ ->disableOriginalConstructor ()
55
+ ->getMock ();
56
+
57
+ $ client ->notify ('not a callable ' );
58
+ }
25
59
}
You can’t perform that action at this time.
0 commit comments