示例#1
0
import bspump.common
import bspump.kafka


class KafkaPipeline(bspump.Pipeline):
    def __init__(self, app, pipeline_id):
        super().__init__(app, pipeline_id)
        self.build(
            bspump.kafka.KafkaSource(app,
                                     self,
                                     "KafkaConnection",
                                     config={'topic': 'messages'}),
            # bspump.common.NullSink(app, self),
            bspump.kafka.KafkaSink(app,
                                   self,
                                   "KafkaConnection",
                                   config={'topic': 'messages2'}),
        )


if __name__ == '__main__':
    app = bspump.BSPumpApplication()

    svc = app.get_service("bspump.PumpService")

    svc.add_connection(bspump.kafka.KafkaConnection(app, "KafkaConnection"))

    svc.add_pipeline(KafkaPipeline(app, "KafkaPipeline"))

    app.run()
示例#2
0
import bspump.common
import bspump.web
import bspump.http


class SamplePipeline(bspump.Pipeline):

	def __init__(self, app, pipeline_id):
		super().__init__(app, pipeline_id)

		self.WebSocketSource = bspump.http.WebSocketSource(app, self)

		self.build(
			self.WebSocketSource,
			bspump.common.PPrintSink(app, self)
		)


if __name__ == '__main__':
	app = bspump.BSPumpApplication(web_listen="0.0.0.0:8080")

	svc = app.get_service("bspump.PumpService")

	# Construct and register Pipeline
	pl = SamplePipeline(app, 'SamplePipeline')
	svc.add_pipeline(pl)

	app.WebContainer.WebApp.router.add_get('/bspump/ws', pl.WebSocketSource.handler)

	app.run()
        self.build(
            self.Source,
            self.Print,
            self.RangeEvaluator,
            # self.Harvester,
            self.Sink)

        self.PubSub.publish("go!")
        self.PubSub.subscribe("bspump.pipeline.cycle_end!", self.on_cycle_end)

    def on_cycle_end(self, event_name, pipeline):
        df1, df2 = self.RangeEvaluator.dump()
        df1.to_csv('./results.csv')
        df2.to_csv('./symptoms.csv')

        self.App.stop()


print('I have started')

if __name__ == '__main__':
    # Registration of the PumpService in ASAB
    app = bspump.BSPumpApplication()  # application object
    my_service = app.get_service("bspump.PumpService")  # service registration

    # Registration of the pipeline MyFirstPipeline
    my_pipeline = MyFirstPipeline(app, 'MyFirstPipeline')
    my_service.add_pipeline(my_pipeline)

    app.run()
示例#4
0
        self.build(
            [
                bspump.common.TeeSource(
                    app, self).bind("SamplePipeline.TeeProcessor"),
            ],
            #bspump.common.JSONParserProcessor(app, self),
            bspump.common.PPrintSink(app, self))

    def catch_error(self, exception, event):
        if isinstance(exception, json.decoder.JSONDecodeError):
            return False
        return True


if __name__ == '__main__':
    app = bspump.BSPumpApplication(web=True)
    svc = app.get_service("bspump.PumpService")

    # Construct timer trigger
    ptrg = bspump.trigger.PubSubTrigger(app, "mymessage!")

    # Construct and register Pipeline
    pl = SamplePipeline(app, 'SamplePipeline', ptrg)
    svc.add_pipeline(pl)

    # Construct and register Pipeline
    pl = SampleInternalPipeline(app, 'SampleInternalPipeline')
    svc.add_pipeline(pl)

    app.run()