in-process 서비스를 다른 프로세스로 전달하기위한 트위스트 메커니즘이 있습니까? 나는트위스트 간 서비스 메시징/버스
from collections import defaultdict
channels = defaultdict(list)
def registerSingle(name, callback):
"""
Similar to register but ensures only one callback is register to a channel
@todo change Exception to something more appropriate
:name str A reasonably coherent name for a callback channel
:callback callable Either a bound method or just a function
"""
global channels
if len(channels[name]) > 0:
raise Exception("Tried to register %s but already has %s registered" % (name, channels))
channels[name].append(callback)
def register(name, callback):
"""
Binds a callback to a named channel
:name str A reasonably coherent name for a callback channel
:callback callable Either a bound method or just a function
"""
global channels
channels[name].append(callback)
def call(name, *args, **kwargs):
"""
Applies the provided arguments to any and all callbacks for a specified channel
:name str A reasonably coherent name for a callback channel
"""
for callback in channels[name]:
callback(*args, **kwargs)
이
foo.py 정말 간단한 예로서이야
from Application.data import bus
def doSomething(fooArg):
print "Hello from Foo, you sent " , fooArg
bus.register("foo.doSomething", doSomething)
bar.py
from Application.data import bus
bus.call("foo.doSomething", "A simple string")
처럼 사용할 수 좋아 보이는 프로토 타입 버스를 썼다 주요 사용 사례는 메모리 데이터 저장소에서 공통점을 공유하는 것입니다. 처음에는 싱글 톤 (singleton)을 사용해 보았지만 단위 테스트로 커버하려고 할 때 너무 많은 문제가있었습니다. 그런 다음 모든 곳의 데이터 저장소에 대한 참조를 전달하려고 시도했지만 데이터 저장소에 100 % 종속되지 않도록 내 응용 프로그램을 변경하고 있다고 생각했습니다.
data.bus 아이디어에 대한 나의 관심사는 기본적으로 지나치게 영광스러운 글로벌 변수라는 것입니다. 그래서 내 질문에, 꼬인 응용 프로그램 내부의 다른 리소스간에 임의의 메시지를 전달할 수 있도록 서비스 버스 또는 메시징 시스템이 비틀어 져 있거나 솔루션에 대한 좋은 데이터 인. 데이터 아이디어가 있습니까?
불행히도 요크 대학교 (University of York)에 네트워킹 문제가있는 것 같습니다. pip 설치 404 및 지정된 홈페이지도 누락되었습니다. – David
여기 Google 코드에서 대체 소스를 찾았습니다. http://code.google.com/p/pylinda/ – David
Twisted가 아마도 여기에서 변경해서는 안되는 데 동의합니다. 특히 내부 프로세스 메시징 인 경우 특히 그렇습니다. – Glyph