File tree Expand file tree Collapse file tree 2 files changed +28
-3
lines changed
implementation/Server/HTTPServer Expand file tree Collapse file tree 2 files changed +28
-3
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ Copyright 2022 The Dapr Authors
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+ Unless required by applicable law or agreed to in writing, software
8
+ distributed under the License is distributed on an "AS IS" BASIS,
9
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ See the License for the specific language governing permissions and
11
+ limitations under the License.
12
+ */
13
+
14
+ /**
15
+ * Http Response Status to be sent back to dapr runtime as subscription response, as per
16
+ * https://docs.dapr.io/reference/api/pubsub_api/#expected-http-response
17
+ */
18
+ export enum SubscribedMessageHttpResponse {
19
+ SUCCESS = "SUCCESS" , // Message is processed successfully
20
+ RETRY = "RETRY" , // Message to be retried by Dapr
21
+ DROP = "DROP" , // Warning is logged and message is dropped
22
+ }
23
+
24
+ export default SubscribedMessageHttpResponse ;
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ import { TypeDaprPubSubCallback } from '../../../types/DaprPubSubCallback.type';
15
15
import IServerPubSub from '../../../interfaces/Server/IServerPubSub' ;
16
16
import HTTPServer from './HTTPServer' ;
17
17
import { Logger } from '../../../logger/Logger' ;
18
+ import SubscribedMessageHttpResponse from '../../../enum/SubscribedMessageHttpResponse.enum' ;
18
19
19
20
// https://docs.dapr.io/reference/api/pubsub_api/
20
21
export default class HTTPServerPubSub implements IServerPubSub {
@@ -45,13 +46,13 @@ export default class HTTPServerPubSub implements IServerPubSub {
45
46
try {
46
47
await cb ( data ) ;
47
48
} catch ( e ) {
48
- this . logger . error ( `subscribe failed: ${ e } ` ) ;
49
- return res . send ( { success : false } ) ;
49
+ this . logger . error ( `[route- ${ topic } ] Message processing failed, dropping : ${ e } ` ) ;
50
+ return res . send ( { status : SubscribedMessageHttpResponse . DROP } ) ;
50
51
}
51
52
52
53
// Let Dapr know that the message was processed correctly
53
54
this . logger . debug ( `[route-${ topic } ] Ack'ing the message` ) ;
54
- return res . send ( { success : true } ) ;
55
+ return res . send ( { status : SubscribedMessageHttpResponse . SUCCESS } ) ;
55
56
} ) ;
56
57
}
57
58
}
You can’t perform that action at this time.
0 commit comments