当前位置: 首页>>代码示例>>Python>>正文


Python Topology.subscribe方法代码示例

本文整理汇总了Python中streamsx.topology.topology.Topology.subscribe方法的典型用法代码示例。如果您正苦于以下问题:Python Topology.subscribe方法的具体用法?Python Topology.subscribe怎么用?Python Topology.subscribe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在streamsx.topology.topology.Topology的用法示例。


在下文中一共展示了Topology.subscribe方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from streamsx.topology.topology import Topology [as 别名]
# 或者: from streamsx.topology.topology.Topology import subscribe [as 别名]
def main():
   local = sys.argv[1] == "local"


   #define needed variables
   COMMANDS_TOPIC = "streamsx/iot/device/commands/send" #topic to publish commands to
   EVENTS_TOPIC = "streamsx/iot/device/events" #topic to subscribe to for events
   incoming_schema =  schema.StreamSchema("tuple <rstring typeId, rstring deviceId, rstring eventId,rstring jsonString>")
   cmd_schema = schema.StreamSchema('tuple<rstring typeId, rstring deviceId, rstring cmdId, rstring jsonString>')


   topo = Topology('ReadingsFromIot')

   #Subscribe to  events
   events = topo.subscribe(EVENTS_TOPIC, incoming_schema,"AllEventsAsJSON")
   sensor_events = events.filter(lambda tuple: tuple["eventId"] == "sensors","SensorEventsAsJSON")
   readings = sensor_events.map(get_event_data,"ReadingsStream")
   readings.print()

   #send a command
   cmd_stream = sensor_events.map(get_cmd, "CommandsAsJSON")
   #convert the commands stream to a SPL structured schema
   commands_to_publish = cmd_stream.map(lambda x : (x["typeId"],x["deviceId"],x["cmdId"],x["jsonString"],), schema = cmd_schema, name="CommandsToPublish")

   commands_to_publish.publish(COMMANDS_TOPIC, cmd_schema)

   if local and len(sys.argv) > 2:
      username = sys.argv[2]
      password = sys.argv[3]
      result = submit_to_service(topo, local, username, password)
   else:
   	  result = submit_to_service(topo, local)

   print("Submitted job to the service, job id = " + str(result.job.id))
开发者ID:IBMStreams,项目名称:samples,代码行数:36,代码来源:read_from_edgent.py

示例2: run

# 需要导入模块: from streamsx.topology.topology import Topology [as 别名]
# 或者: from streamsx.topology.topology.Topology import subscribe [as 别名]
    def run(self, context="DISTRIBUTED"):
        ## Create topology
        topo = Topology("HealthcareDemo")

        ## Ingest, preprocess and aggregate patient data
        patientData = topo.subscribe("ingest-physionet", schema.CommonSchema.Json) \
                          .map(functions.identity) \
                          .filter(healthcare_functions.PatientFilter(self.patient_id)) \
                          .transform(healthcare_functions.GenTimestamp(self.sample_rate)) \
                          .transform(SlidingWindow(length=self.sample_rate, trigger=self.sample_rate-1)) \
                          .transform(healthcare_functions.aggregate) \

        ## Calculate RPeak and RR delta
        rpeak_data_stream = patientmonitoring_functions.streaming_rpeak(patientData, self.sample_rate, data_label='ECG Lead II')

        ## Create a view of the data
        self.view_data = rpeak_data_stream.view()

        ## Compile Python Streams application and submit job
        streamsx.topology.context.submit(context, topo.graph, username=self.username, password=self.password)
开发者ID:IBMStreams,项目名称:streamsx.health,代码行数:22,代码来源:healthcare_patient.py


注:本文中的streamsx.topology.topology.Topology.subscribe方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。