aboutsummaryrefslogtreecommitdiffstats
path: root/catalog/pub/Dmaap_lib/dmaap/consumer.py
diff options
context:
space:
mode:
Diffstat (limited to 'catalog/pub/Dmaap_lib/dmaap/consumer.py')
-rw-r--r--catalog/pub/Dmaap_lib/dmaap/consumer.py30
1 files changed, 15 insertions, 15 deletions
diff --git a/catalog/pub/Dmaap_lib/dmaap/consumer.py b/catalog/pub/Dmaap_lib/dmaap/consumer.py
index 054791c..d817b81 100644
--- a/catalog/pub/Dmaap_lib/dmaap/consumer.py
+++ b/catalog/pub/Dmaap_lib/dmaap/consumer.py
@@ -1,48 +1,47 @@
-# Copyright (c) 2019, CMCC Technologies Co., Ltd.
-# Licensed under the Apache License, Version 2.0 (the "License")
+# Copyright (c) 2019, CMCC Technologies. Co., Ltd.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
-# http://www.apache.org/licenses/LICENSE-2.0
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
-
import base64
+import datetime
import hmac
import json
import logging
-import datetime
-import requests
from hashlib import sha1
-from ..pub.exceptions import DmaapClientException
+import requests
+
+from catalog.pub.Dmaap_lib.pub.exceptions import DmaapClientException
logger = logging.getLogger(__name__)
class ConsumerClient:
- def __init__(self, host, topic, consumer_group, consumer_id, timeout_ms=-1, limit=-1, filter='',
- api_key='', api_secret=''):
- self.host = host
+ def __init__(self, base_url, topic, consumer_group, consumer_id, timeout_ms=-1, limit=-1, filter=''):
+ self.base_url = base_url
self.topic = topic
self.group = consumer_group
self.comsumer_id = consumer_id
self.timeout_ms = timeout_ms
self.limit = limit
self.filter = filter
- self.api_key = api_key
- self.api_secret = api_secret
def set_api_credentials(self, api_key, api_secret):
-
self.api_key = api_key
self.api_secret = api_secret
def create_url(self):
- url = "http://%s/events/%s/%s/%s" % (self.host, self.topic, self.group, self.comsumer_id)
+ url = self.base_url + "/events/%s/%s/%s" % (self.topic, self.group, self.comsumer_id)
add_url = ""
if self.timeout_ms > -1:
add_url += "timeout=%s" % self.timeout_ms
@@ -81,7 +80,8 @@ class ConsumerClient:
ret = requests.get(url)
logger.info("Status code is %s, detail is %s.", ret.status_code, ret.json())
if ret.status_code != 200:
- raise DmaapClientException('Call dmaap failed. Status code is %s, detail is %s.' % (ret.status_code, ret.json()))
+ raise DmaapClientException(
+ 'Call dmaap failed. Status code is %s, detail is %s.' % (ret.status_code, ret.json()))
data = ret.json()
for msg in data:
msg = json.loads(msg)