File tree Expand file tree Collapse file tree 4 files changed +50
-1
lines changed Expand file tree Collapse file tree 4 files changed +50
-1
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,11 @@ CHANGELOG
11
11
changed from ` Serializer ` to ` PhpSerializer ` inside ` AmqpReceiver ` ,
12
12
` AmqpSender ` , ` AmqpTransport ` and ` AmqpTransportFactory ` .
13
13
14
+ * Added ` TransportException ` to mark an exception transport-related
15
+
16
+ * [ BC BREAK] If listening to exceptions while using ` AmqpSender ` , ` \AMQPException ` is
17
+ no longer thrown in favor of ` TransportException ` .
18
+
14
19
4.2.0
15
20
-----
16
21
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the Symfony package.
5
+ *
6
+ * (c) Fabien Potencier <[email protected] >
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ namespace Symfony \Component \Messenger \Exception ;
13
+
14
+ /**
15
+ * @author Eric Masoero <[email protected] >
16
+ *
17
+ * @experimental in 4.2
18
+ */
19
+ class TransportException extends RuntimeException
20
+ {
21
+ }
Original file line number Diff line number Diff line change @@ -37,4 +37,22 @@ public function testItSendsTheEncodedMessage()
37
37
$ sender = new AmqpSender ($ connection , $ serializer );
38
38
$ sender ->send ($ envelope );
39
39
}
40
+
41
+ /**
42
+ * @expectedException Symfony\Component\Messenger\Exception\TransportException
43
+ */
44
+ public function testItThrowsATransportExceptionIfItCannotSendTheMessage ()
45
+ {
46
+ $ envelope = new Envelope (new DummyMessage ('Oy ' ));
47
+ $ encoded = ['body ' => '... ' , 'headers ' => ['type ' => DummyMessage::class]];
48
+
49
+ $ serializer = $ this ->getMockBuilder (SerializerInterface::class)->getMock ();
50
+ $ serializer ->method ('encode ' )->with ($ envelope )->willReturnOnConsecutiveCalls ($ encoded );
51
+
52
+ $ connection = $ this ->getMockBuilder (Connection::class)->disableOriginalConstructor ()->getMock ();
53
+ $ connection ->method ('publish ' )->with ($ encoded ['body ' ], $ encoded ['headers ' ])->willThrowException (new \AMQPException ());
54
+
55
+ $ sender = new AmqpSender ($ connection , $ serializer );
56
+ $ sender ->send ($ envelope );
57
+ }
40
58
}
Original file line number Diff line number Diff line change 12
12
namespace Symfony \Component \Messenger \Transport \AmqpExt ;
13
13
14
14
use Symfony \Component \Messenger \Envelope ;
15
+ use Symfony \Component \Messenger \Exception \TransportException ;
15
16
use Symfony \Component \Messenger \Transport \Sender \SenderInterface ;
16
17
use Symfony \Component \Messenger \Transport \Serialization \PhpSerializer ;
17
18
use Symfony \Component \Messenger \Transport \Serialization \SerializerInterface ;
@@ -41,7 +42,11 @@ public function send(Envelope $envelope): Envelope
41
42
{
42
43
$ encodedMessage = $ this ->serializer ->encode ($ envelope );
43
44
44
- $ this ->connection ->publish ($ encodedMessage ['body ' ], $ encodedMessage ['headers ' ]);
45
+ try {
46
+ $ this ->connection ->publish ($ encodedMessage ['body ' ], $ encodedMessage ['headers ' ]);
47
+ } catch (\AMQPException $ e ) {
48
+ throw new TransportException ('Current transport was not able to send given message, please try again ' );
49
+ }
45
50
46
51
return $ envelope ;
47
52
}
You can’t perform that action at this time.
0 commit comments