X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=src%2Fo2ims%2Fadapter%2Fredis_eventpublisher.py;fp=src%2Fo2ims%2Fadapter%2Fredis_eventpublisher.py;h=835c72c9992583417bf9ca2c5f5882d13e50e4d8;hb=8339c9a882a586578b37f44a504e21c5208611c0;hp=0000000000000000000000000000000000000000;hpb=40728ef923af791f42582a657c17abdaeec82b6d;p=pti%2Fo2.git diff --git a/src/o2ims/adapter/redis_eventpublisher.py b/src/o2ims/adapter/redis_eventpublisher.py new file mode 100644 index 0000000..835c72c --- /dev/null +++ b/src/o2ims/adapter/redis_eventpublisher.py @@ -0,0 +1,30 @@ +# Copyright (C) 2021 Wind River Systems, Inc. +# +# 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 +# +# 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 json +import logging +from dataclasses import asdict +import redis + +from o2ims import config +from o2ims.domain import events + +logger = logging.getLogger(__name__) + +r = redis.Redis(**config.get_redis_host_and_port()) + + +def publish(channel, event: events.Event): + logging.info("publishing: channel=%s, event=%s", channel, event) + r.publish(channel, json.dumps(asdict(event)))