本文整理匯總了Java中org.zeromq.ZMQ.proxy方法的典型用法代碼示例。如果您正苦於以下問題:Java ZMQ.proxy方法的具體用法?Java ZMQ.proxy怎麽用?Java ZMQ.proxy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.zeromq.ZMQ
的用法示例。
在下文中一共展示了ZMQ.proxy方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import org.zeromq.ZMQ; //導入方法依賴的package包/類
public static void main (String[] args) {
// Prepare our context and sockets
Context context = ZMQ.context(1);
// Socket facing clients
Socket frontend = context.socket(ZMQ.ROUTER);
frontend.bind("tcp://*:5559");
// Socket facing services
Socket backend = context.socket(ZMQ.DEALER);
backend.bind("tcp://*:5560");
// Start the proxy
ZMQ.proxy (frontend, backend, null);
// We never get here but clean up anyhow
frontend.close();
backend.close();
context.term();
}
示例2: run
import org.zeromq.ZMQ; //導入方法依賴的package包/類
@Override
public void run() {
ctx = new ZContext();
frontend = ctx.createSocket(ZMQ.ROUTER);
frontend.bind("tcp://*:5570");
backend = ctx.createSocket(ZMQ.DEALER);
backend.bind("inproc://backend");
// Launch pool of worker threads, precise number is not critical
for (int threadNbr = 0; threadNbr < 2; threadNbr++) {
new Thread(new JeroMQServerWorker(ctx)).start();
}
// Connect backend to frontend via a proxy
ZMQ.proxy(frontend, backend, null);
}
示例3: start
import org.zeromq.ZMQ; //導入方法依賴的package包/類
public synchronized void start() {
Log.write("Starting service on " + this.port);
this.context = ZMQ.context(1);
this.internal = context.socket(ZMQ.DEALER);
this.internal.bind(getInternalAddress());
this.external = context.socket(ZMQ.ROUTER);
this.external.bind(getExternalAddress());
startWorkers();
try {
ZMQ.proxy(external, internal, null);
} catch (ZError.IOException ex) {
Throwable cause = ex.getCause();
if (cause instanceof ClosedChannelException) {
stop();
} else {
throw ex;
}
}
}
示例4: run
import org.zeromq.ZMQ; //導入方法依賴的package包/類
@Override
public void run() {
ZContext ctx = new ZContext();
// Frontend socket talks to clients over TCP
Socket frontend = ctx.createSocket(ZMQ.ROUTER);
frontend.bind("tcp://*:5570");
// Backend socket talks to workers over inproc
Socket backend = ctx.createSocket(ZMQ.DEALER);
backend.bind("inproc://backend");
// Launch pool of worker threads, precise number is not critical
for (int threadNbr = 0; threadNbr < requestHanlderPoolSize; threadNbr++) {
try {
new Thread(new server_worker(ctx)).start();
} catch (Exception e) {
// Does nothing as a warning was already issued.
}
}
// Connect backend to frontend via a proxy
ZMQ.proxy(frontend, backend, null);
LOG.info("ZMQNBIServerPool - Exiting MAIN server thread");
frontend.unbind("tcp://*:5570");
backend.unbind("inproc://backend");
ctx.destroySocket(frontend);
ctx.destroySocket(backend);
ctx.destroy();
}
示例5: run
import org.zeromq.ZMQ; //導入方法依賴的package包/類
/**
* This is where ZeroMQ and MessagePack are implemented, and the long running process initialized to receive incoming
* messages.
* <p>
* Upon executing the userland source code any action functions registered MUST be stored so they MAY be referenced
* by either "request" or "response" in the case of Middleware, or by the specific action name in the case of a
* Service. This reference SHOULD then be used to effectively route messages received by the SDK to their relevant
* action function.
*/
public void run() {
if (this.action != null) {
Scanner in = new Scanner(System.in);
String payload = in.next();
try {
S commandReply = processRequest(this.action, getSdkCommand(this.action, null, payload));
System.out.print(serializer.serializeInJson(commandReply));
} catch (Exception e) {
Logger.log(e);
runErrorCallback();
try {
System.out.print(serializer.serializeInJson(getErrorPayload(e)));
} catch (JsonProcessingException e1) {
Logger.log(e1);
System.out.print("");
}
}
} else {
startSocket();
setWorkers();
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override
public void run() {
if (shutdownCallable != null) {
Component.this.runShutdown();
}
if (!stopped) {
Component.this.stopSocket();
}
}
}));
ZMQ.proxy(router, dealer, null);
}
}
示例6: run
import org.zeromq.ZMQ; //導入方法依賴的package包/類
public void run() {
ZMQ.Socket middleendreceiver = context.socket(ZMQ.SUB);
middleendreceiver.connect("inproc://sender-middleend-"+ fid);
middleendreceiver.subscribe("".getBytes()); //dummy topic.
ZMQ.Socket backend = context.socket(ZMQ.PUSH);
backend.bind("tcp://*:" + port);
ZMQ.proxy(middleendreceiver, backend, null);
}
示例7: run
import org.zeromq.ZMQ; //導入方法依賴的package包/類
@Override
public void run() {
System.out.println("ZMQ: RUN CALLED");
ZMQ.proxy(external, internal, null);
}
示例8: ZeroMQProxy
import org.zeromq.ZMQ; //導入方法依賴的package包/類
public ZeroMQProxy (final int portOUT,final int portMETA){
kryo.register(DataField[].class);
ctx = Main.getZmqContext();
subscriberX = ctx.createSocket(ZMQ.XSUB);
publisherX = ctx.createSocket(ZMQ.XPUB);
publisherX.setXpubVerbose(true);
publisherX.setHWM(0);
subscriberX.setHWM(0);
publisherX.bind("tcp://*:"+portOUT);
clients = ctx.createSocket(ZMQ.REP);
clients.bind ("tcp://*:"+portMETA);
Thread dataProxy = new Thread(new Runnable(){
@Override
public void run() {
ZMQ.proxy(subscriberX, publisherX, null);
}
});
dataProxy.setName("ZMQ-PROXY-Thread");
dataProxy.start();
Thread metaResponder = new Thread(new Runnable(){
@Override
public void run() {
while (true) {
String request = clients.recvStr (0);
String [] parts = request.split("\\?");
if (parts.length > 1){
try{
long startTime = System.currentTimeMillis();
if (parts.length > 2){
startTime = Long.parseLong(parts[2]);
}
ZeroMQDeliverySync d = new ZeroMQDeliverySync(parts[0], parts[1]);
final DefaultDistributionRequest distributionReq = DefaultDistributionRequest.create(d, Mappings.getVSensorConfig(parts[0]), "select * from "+parts[0], startTime);
logger.info("ZMQ request received: "+distributionReq.toString());
DataDistributer.getInstance(d.getClass()).addListener(distributionReq);
}catch (Exception e){
logger.warn("ZMQ request parsing error: " + request, e);
}
}
byte[] b=new byte[0];
ByteArrayOutputStream bais = new ByteArrayOutputStream();
Output o = new Output(bais);
kryo.writeObjectOrNull(o,structures.get(parts[0]),DataField[].class);
o.close();
b = bais.toByteArray();
clients.send(b, 0);
}
}
});
metaResponder.setName("ZMQ-META-Thread");
metaResponder.start();
}