Skip to content

Commit

Permalink
Pubsub working now!
Browse files Browse the repository at this point in the history
  • Loading branch information
craig8 committed Sep 24, 2024
1 parent 396923a commit c358374
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "volttron-listener"
version = "1.0.1"
version = "1.0.3"
description = "The volttron-listener agent allows publishing of message bus traffic to standard out."
authors = ["VOLTTRON Team <[email protected]>"]
license = "Apache License 2.0"
Expand Down
17 changes: 12 additions & 5 deletions src/listener/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,20 @@
#
# ===----------------------------------------------------------------------===
# }}}

import logging
import sys
from pprint import pformat
import datetime

from volttron.utils.commands import vip_main
from volttron.client.messaging.health import STATUS_GOOD
from volttron.client.vip.agent import Agent, Core, PubSub
from volttron.client.logs import get_logger, setup_logging
from volttron.client.logs import setup_logging
import volttron.utils as utils

setup_logging()
_log = get_logger()
setup_logging(level=logging.DEBUG)
_log = utils.get_logger()
#_log.setLevel(logging.DEBUG)
__version__ = '4.0'
DEFAULT_MESSAGE = 'Listener Message'
DEFAULT_HEARTBEAT_PERIOD = 30
Expand Down Expand Up @@ -80,13 +81,16 @@ def onsetup(self, sender, **kwargs):
@Core.receiver('onstart')
def onstart(self, sender, **kwargs):
# TODO: Bring back version?
pass
#_log.debug("VERSION IS: {}".format(self.core.version()))
if self._heartbeat_period != 0:
_log.debug(f"Heartbeat starting for {self.core.identity} published every {self._heartbeat_period}")
self.vip.heartbeat.start_with_period(self._heartbeat_period)
self.vip.health.set_status(STATUS_GOOD, self._message)

@PubSub.subscribe('pubsub', '', all_platforms=True)
self.vip.pubsub.subscribe(peer='pubsub', prefix='', callback=self.on_match)

#@PubSub.subscribe('pubsub', '', all_platforms=True)
def on_match(self, peer, sender, bus, topic, headers, message):
"""Use match_all to receive all messages and print them out."""
self._logfn(
Expand All @@ -103,6 +107,9 @@ def main():
vip_main(ListenerAgent, version=__version__)
except Exception as e:
_log.exception('unhandled exception')
_log.exception(e)
finally:
_log.debug("Exiting")


if __name__ == '__main__':
Expand Down

0 comments on commit c358374

Please sign in to comment.