17
17
18
18
package org .apache .eventmesh .protocol .amqp .resolver ;
19
19
20
- import com .alibaba .fastjson .JSON ;
21
- import com .rabbitmq .client .AMQP .BasicProperties ;
22
- import io .cloudevents .CloudEvent ;
23
- import io .cloudevents .core .v1 .CloudEventBuilder ;
24
- import org .apache .commons .collections4 .MapUtils ;
25
20
import org .apache .eventmesh .common .protocol .amqp .AmqpMessage ;
26
21
import org .apache .eventmesh .common .protocol .amqp .common .ProtocolKey ;
27
22
import org .apache .eventmesh .protocol .amqp .AMQPProtocolConstant ;
28
23
24
+ import org .apache .commons .collections4 .MapUtils ;
25
+
29
26
import java .net .URI ;
30
27
import java .util .HashMap ;
31
28
import java .util .Map ;
32
29
import java .util .Objects ;
33
30
import java .util .UUID ;
34
31
32
+ import io .cloudevents .CloudEvent ;
33
+ import io .cloudevents .core .v1 .CloudEventBuilder ;
34
+
35
+ import com .alibaba .fastjson .JSON ;
36
+ import com .rabbitmq .client .impl .AMQContentHeader ;
37
+
35
38
/**
36
39
* Resolve AmqpMessage or CloudEvent
37
40
*/
@@ -46,19 +49,19 @@ public static CloudEvent buildEvent(AmqpMessage amqpMessage) {
46
49
String queueName = "" ;
47
50
Map <String , Object > extendInfo = amqpMessage .getExtendInfo ();
48
51
if (MapUtils .isNotEmpty (extendInfo )) {
49
- // routingKey, exchange去掉,路由信息在这之前完成
52
+ // removed routingKey, exchange, routing should be finished before
50
53
// routingKey = extendInfo.get(ProtocolKey.ROUTING_KEY).toString();
51
54
// exchange = extendInfo.get(ProtocolKey.EXCHANGE).toString();
52
55
queueName = extendInfo .get (ProtocolKey .QUEUE_NAME ).toString ();
53
56
}
54
- BasicProperties amqBasicProperties = amqpMessage .getContentHeader ();
57
+ AMQContentHeader amqContentHeader = amqpMessage .getContentHeader ();
55
58
byte [] contentBody = amqpMessage .getContentBody ();
56
59
cloudEventBuilder
57
60
.withId (id )
58
61
.withSource (source )
59
62
.withType (AMQPProtocolConstant .PROTOCOL_NAME )
60
63
.withSubject (queueName )
61
- .withExtension (ProtocolKey .BASIC_PROPERTIES , JSON .toJSONString (amqBasicProperties ))
64
+ .withExtension (ProtocolKey .AMQ_CONTEND_HEADER , JSON .toJSONString (amqContentHeader ))
62
65
.withData (contentBody );
63
66
return cloudEventBuilder .build ();
64
67
}
@@ -70,8 +73,8 @@ public static AmqpMessage buildAmqpMessage(CloudEvent cloudEvent) {
70
73
extendInfo .put (ProtocolKey .ROUTING_KEY , routingKey );
71
74
extendInfo .put (ProtocolKey .EXCHANGE , exchange );
72
75
byte [] contentBody = Objects .requireNonNull (cloudEvent .getData ()).toBytes ();
73
- BasicProperties amqBasicProperties = JSON .parseObject (Objects .requireNonNull (cloudEvent .getExtension (ProtocolKey .BASIC_PROPERTIES )).toString (), BasicProperties .class );
74
- return new AmqpMessage (amqBasicProperties , contentBody , extendInfo );
76
+ AMQContentHeader amqContentHeader = JSON .parseObject (Objects .requireNonNull (cloudEvent .getExtension (ProtocolKey .AMQ_CONTEND_HEADER )).toString (), AMQContentHeader .class );
77
+ return new AmqpMessage (amqContentHeader , contentBody , extendInfo );
75
78
}
76
79
77
80
}
0 commit comments