File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -23,15 +23,21 @@ class StompContext implements Context
2323 */
2424 private $ stomp ;
2525
26+ /**
27+ * @var bool
28+ */
29+ private $ useExchangePrefix ;
30+
2631 /**
2732 * @var callable
2833 */
2934 private $ stompFactory ;
3035
3136 /**
3237 * @param BufferedStompClient|callable $stomp
38+ * @param bool $useExchangePrefix
3339 */
34- public function __construct ($ stomp )
40+ public function __construct ($ stomp, $ useExchangePrefix = true )
3541 {
3642 if ($ stomp instanceof BufferedStompClient) {
3743 $ this ->stomp = $ stomp ;
@@ -40,6 +46,8 @@ public function __construct($stomp)
4046 } else {
4147 throw new \InvalidArgumentException ('The stomp argument must be either BufferedStompClient or callable that return BufferedStompClient. ' );
4248 }
49+
50+ $ this ->useExchangePrefix = $ useExchangePrefix ;
4351 }
4452
4553 /**
@@ -84,7 +92,7 @@ public function createTopic(string $name): Topic
8492 {
8593 if (0 !== strpos ($ name , '/ ' )) {
8694 $ destination = new StompDestination ();
87- $ destination ->setType (StompDestination::TYPE_EXCHANGE );
95+ $ destination ->setType ($ this -> useExchangePrefix ? StompDestination::TYPE_EXCHANGE : StompDestination:: TYPE_TOPIC );
8896 $ destination ->setStompName ($ name );
8997
9098 return $ destination ;
Original file line number Diff line number Diff line change @@ -79,7 +79,7 @@ public function testCreateQueueShouldCreateDestinationIfNameIsFullDestinationStr
7979 $ this ->assertEquals ('/amq/queue/name/routing-key ' , $ destination ->getQueueName ());
8080 }
8181
82- public function testShouldCreateTopicInstance ()
82+ public function testShouldCreateTopicInstanceWithExchangePrefix ()
8383 {
8484 $ context = new StompContext ($ this ->createStompClientMock ());
8585
@@ -91,6 +91,18 @@ public function testShouldCreateTopicInstance()
9191 $ this ->assertSame (StompDestination::TYPE_EXCHANGE , $ topic ->getType ());
9292 }
9393
94+ public function testShouldCreateTopicInstanceWithTopicPrefix ()
95+ {
96+ $ context = new StompContext ($ this ->createStompClientMock (), false );
97+
98+ $ topic = $ context ->createTopic ('the name ' );
99+
100+ $ this ->assertInstanceOf (StompDestination::class, $ topic );
101+ $ this ->assertSame ('/topic/the name ' , $ topic ->getQueueName ());
102+ $ this ->assertSame ('/topic/the name ' , $ topic ->getTopicName ());
103+ $ this ->assertSame (StompDestination::TYPE_TOPIC , $ topic ->getType ());
104+ }
105+
94106 public function testCreateTopicShouldCreateDestinationIfNameIsFullDestinationString ()
95107 {
96108 $ context = new StompContext ($ this ->createStompClientMock ());
You can’t perform that action at this time.
0 commit comments