dta25920 2016-03-10 14:00
浏览 177
已采纳

用不同语言编写的ZeroMQ套接字的兼容性

I've built an app written on python, based on ZeroMQ, but now I'm facing perfomance issues. So I decided to rewrite some modules of my app using, let's say, Golang. But when I try to establish messaging between sockets, implemented by different languages, anything does not work.

I've searched so far, but I didn't find any info about compatibility problems of ZeroMQ using different languages.

So the question is: Can I use golang for server implementation based on ZeroMQ and client written on python to connect to it?
Or do I have to use only one language?

EDIT: here are typical server and client that I'm trying to get working properly

server:

import zmqctx = zmq.Context()
sock = ctx.socket(zmq.REP)
sock.bind("tcp://*:57000")
msg = sock.recv()

client:

package main

import (
    zmq "github.com/pebbe/zmq4"
)

func main() {

    ctx, _ := zmq.NewContext()
    sock, _ := ctx.NewSocket(zmq.REQ)

    sock.Connect("tcp://localhost:57000")
    sock.Send("simple message", 0)
}

Server stucks at sock.recv()

  • 写回答

2条回答 默认 最新

  • doupao6011 2016-03-10 14:12
    关注

    Programming languages are able to communicate with each other -- yes, you can write a server in Go and a client in Python and have them communicate with each other.

    If you're trying to communicate using raw sockets, look at the documentation for your desired languages and make sure that the serialized data match in structure.

    e.g. You could decide on a struct and implement your payload in Python or code and then match that structure in Go (there may be a better/stdlib way in Go; I'm not very experienced in this language). The potential maintenance and implementation headache in worrying about these details is why people use higher-level protocols -- exactly a good use case for ZeroMQ.

    If you're using a message queue as the backbone of your operation, simply use that as the shared protocol. If your Python code can speak with ZeroMQ, then it's doing its job correctly -- there's no need for your Go code to know it's speaking to Python.

    In this case, your new Go server would bind to ZeroMQ, your Python client would bind to ZeroMQ, and your two heterogenous languages need to know nothing about each other.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 dspbuilder中使用signalcompiler时报错Error during compilation: Fitter failed,求解决办法
  • ¥15 gwas 分析-数据质控之过滤稀有突变中出现的问题
  • ¥15 没有注册类 (异常来自 HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
  • ¥15 知识蒸馏实战博客问题
  • ¥15 用PLC设计纸袋糊底机送料系统
  • ¥15 simulink仿真中dtc控制永磁同步电机如何控制开关频率
  • ¥15 用C语言输入方程怎么
  • ¥15 网站显示不安全连接问题
  • ¥15 51单片机显示器问题
  • ¥20 关于#qt#的问题:Qt代码的移植问题