How to use the autobahn.wamp.types.PublishOptions function in autobahn

To help you get started, we’ve selected a few autobahn examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github crossbario / autobahn-python / examples / twisted / wamp / work / test_rawsocket.py View on Github external
def onJoin(self, details):

        def on_event(i):
            print("Got event: {}".format(i))

        yield self.subscribe(on_event, 'com.myapp.topic1')

        counter = 0
        while True:
            self.publish('com.myapp.topic1', counter, options=types.PublishOptions(excludeMe=False))
            counter += 1
            yield sleep(1)
github crossbario / crossbar / crossbar / worker / container.py View on Github external
def on_connect_success(proto):
            component = ContainerComponent(component_id, config, proto, None)
            self.components[component_id] = component

            # publish event "on_component_start" to all but the caller
            #
            uri = self._uri_prefix + '.on_component_started'

            component_started = {
                'id': component_id,
                'config': config
            }

            self.publish(uri, component_started, options=PublishOptions(exclude=details.caller))

            return component_started
github crossbario / crossbar / crossbar / router / broker.py View on Github external
def _publish(subscription):
                        service_session = self._router._realm.session

                        # FIXME: what about exclude_authid as colleced from forward_for? like we do elsewhere in this file!
                        options = types.PublishOptions(
                            correlation_id=None,
                            correlation_is_anchor=True,
                            correlation_is_last=False
                        )

                        if was_subscribed:
                            service_session.publish(
                                'wamp.subscription.on_unsubscribe',
                                session._session_id,
                                subscription.id,
                                options=options,
                            )

                        if was_deleted:
                            options.correlation_is_last = True
                            service_session.publish(
github crossbario / crossbar / crossbar / bridge / rest / webhook.py View on Github external
def _process(self, request, event):

        # The topic we're going to send to
        topic = self._options["topic"]

        message = {}
        message["headers"] = {
            native_string(x): [native_string(z) for z in y]
            for x, y in request.requestHeaders.getAllRawHeaders()}
        message["body"] = event

        publish_options = PublishOptions(acknowledge=True)

        def _succ(result):
            response_text = self._options.get("success_response", "OK").encode('utf8')
            return self._complete_request(
                request, 202, response_text,
                reason="Successfully sent webhook from {ip} to {topic}",
                topic=topic,
                ip=request.getClientIP(),
                log_category="AR201",
            )

        def _err(result):
            response_text = self._options.get("error_response", "NOT OK").encode('utf8')
            error_message = str(result.value)
            authorization_problem = False
            if isinstance(result.value, ApplicationError):
github crossbario / crossbar / crossbar / worker / controller.py View on Github external
return
            # raise ApplicationError('crossbar.error.operation_in_progress', 'cannot shutdown - the worker is already shutting down')
        else:
            self._is_shutting_down = True

        self.log.info("Shutdown of worker requested!")

        # publish management API event
        #
        yield self.publish(
            '{}.on_shutdown_requested'.format(self._uri_prefix),
            {
                'who': details.caller if details else None,
                'when': utcnow()
            },
            options=PublishOptions(exclude=details.caller if details else None, acknowledge=True)
        )

        # we now call self.leave() to initiate the clean, orderly shutdown of the native worker.
        # the call is scheduled to run on the next reactor iteration only, because we want to first
        # return from the WAMP call when this procedure is called from the node controller
        #
        self._reactor.callLater(0, self.leave)
github crossbario / crossbar / crossbar / node / controller.py View on Github external
# now (immediately before actually forking) signal the starting of the worker
        #
        starting_info = {
            'id': worker_id,
            'status': worker.status,
            'created': utcstr(worker.created),
            'who': worker.who,
        }

        # the caller gets a progressive result ..
        if details.progress:
            details.progress(starting_info)

        # .. while all others get an event
        self.publish(starting_topic, starting_info, options=PublishOptions(exclude=details.caller))

        # now actually fork the worker ..
        #
        self.log.info('{worker_logname} "{worker_id}" process starting ..',
                      worker_logname=worker_logname, worker_id=worker_id)
        self.log.debug('{worker_logname} "{worker_id}" process using command line "{cli}" ..',
                       worker_logname=worker_logname, worker_id=worker_id, cli=' '.join(args))

        d = ep.connect(transport_factory)

        def on_connect_success(proto):

            # this seems to be called immediately when the child process
            # has been forked. even if it then immediately fails because
            # e.g. the executable doesn't even exist. in other words,
            # I'm not sure under what conditions the deferred will
github crossbario / crossbar / crossbar / worker / router.py View on Github external
def publish_stopped(session, stop_details):
            self.log.info(
                "stopped component: {session} id={session_id}",
                session=class_name(session),
                session_id=session._session_id,
            )
            topic = self._uri_prefix + '.on_component_stop'
            event = {'id': id}
            caller = details.caller if details else None
            self.publish(topic, event, options=PublishOptions(exclude=caller))
            if not started_d.called:
                started_d.errback(Exception("Session left before being ready"))
            return event
github crossbario / crossbar / crossbar / worker / container.py View on Github external
if isinstance(proto, WampWebSocketClientProtocol):
                proto.onClose = partial(close_wrapper, proto.onClose)

            elif isinstance(proto, WampRawSocketClientProtocol):
                # FIXME: doesn't work without guard, since proto_.session is not yet there when
                # proto comes into existance ..
                if proto._session:
                    proto._session.onClose = partial(close_wrapper, proto._session.onClose)
            else:
                raise Exception("logic error")

            # publish event "on_component_start" to all but the caller
            #
            topic = self._uri_prefix + '.container.on_component_start'
            event = {u'id': id}
            self.publish(topic, event, options=PublishOptions(exclude=details.caller))
            return event
github crossbario / crossbar / crossbar / common / process.py View on Github external
duration = int(round(1000. * (rtime() - started)))

        on_gc_finished = '{}.on_gc_finished'.format(self._uri_prefix)
        self.publish(
            on_gc_finished,
            {
                'requester': {
                    'session_id': details.caller,
                    # FIXME:
                    'auth_id': None,
                    'auth_role': None
                },
                'duration': duration
            },
            options=PublishOptions(exclude=details.caller)
        )

        return duration