标签: thrift-protocol

Python中的非阻塞Thrift服务器

在下面的代码片段中,我试图在python中创建一个非阻塞的thrift服务器.

    # set handler to our implementation
    handler = ServiceHandler()

    processor = MyService.Processor(handler)
    transport = TSocket.TServerSocket(port=port)
    tfactory = TTransport.TFramedTransport(transport)  
    pfactory = TBinaryProtocol.TBinaryProtocolFactory()

    # set server
    server = TServer.TThreadedServer(processor, transport, tfactory, pfactory)

    print 'Python Server has started listening on port ' + str(port)
    print '################################################'
    server.serve()
Run Code Online (Sandbox Code Playgroud)

当python客户端尝试连接具有上述代码片段的服务器时,我收到以下错误.你能告诉我导致这个错误的原因吗?可能我错过了一些东西.

    Exception in thread Thread-1:
    Traceback (most recent call last):
    File "/usr/lib64/python2.6/threading.py", line 522, in __bootstrap_inner
    self.run()
    File "/usr/lib64/python2.6/threading.py", line 477, in run
    self.__target(*self.__args, **self.__kwargs)
    File "/usr/local/lib64/python2.6/site-packages/thrift/server/TServer.py", line 114, in handle
    itrans = self.inputTransportFactory.getTransport(client)
    AttributeError: …
Run Code Online (Sandbox Code Playgroud)

python thrift nonblocking thrift-protocol

5
推荐指数
1
解决办法
5223
查看次数

phpcassa连接池

我有一个数据访问类,在实例化上设置三个phpcassa连接池,如下所示:


try {
  $this->cache = new ConnectionPool(
    BSCACHE_KEYSPACE,
    explode(',', BSCACHE_SERVERS),
    null, null, null, null, null,
    array(
      'username' => BSCACHE_USERNAME,
      'password' => BSCACHE_PASSWORD
    )
  );
  $this->indexCache = new ConnectionPool(
    INDEXCACHE_KEYSPACE,
    explode(',', INDEXCACHE_SERVERS),
    null, null, null, null, null,
    array(
      'username' => INDEXCACHE_USERNAME,
      'password' => INDEXCACHE_PASSWORD
    )
  );

  $this->metaCache = new ConnectionPool(
    METACACHE_KEYSPACE,
    explode(',', METACACHE_SERVERS),
    null, null, null, null, null,
    array(
      'username' => METACACHE_USERNAME,
      'password' => METACACHE_PASSWORD
    )
  );
} catch (Exception $e) {
  return array($this->error['connection']);
}

我最近在zend的php服务器上使用代码跟踪功能对这个类进行了一点性能审计,并注意到这三个连接池的设置耗费了大约100ms.考虑到每个连接每次实例化只使用一次或两次,这就是输入连接的大量时间.

任何人都知道任何巧妙的技巧可以让我一次构建这些连接池并让它们在类的实例化之间共享?也许有一些简单的方法可以立即发生更高级的PHP开发人员? …

php connection-pooling cassandra thrift-protocol phpcassa

5
推荐指数
1
解决办法
926
查看次数

节俭 - 从简单的JSON转换

我创建了以下Thrift对象:

struct Student{
        1: string id;
        2: string firstName;
        3: string lastName
}
Run Code Online (Sandbox Code Playgroud)

现在我想从JSON中读取这个对象.根据这篇文章,这是可能的

所以我写了下面的代码:

String json = "{\"id\":\"aaa\",\"firstName\":\"Danny\",\"lastName\":\"Lesnik\"}";
    StudentThriftObject s = new StudentThriftObject();
    byte[] jsonAsByte = json.getBytes("UTF-8");
    TMemoryBuffer memBuffer = new TMemoryBuffer(jsonAsByte.length);
    memBuffer.write(jsonAsByte);

    TProtocol proto = new TJSONProtocol(memBuffer);
    s.read(proto);
Run Code Online (Sandbox Code Playgroud)

我得到的是以下异常:

Exception in thread "main" org.apache.thrift.protocol.TProtocolException: Unexpected character:i
    at org.apache.thrift.protocol.TJSONProtocol.readJSONSyntaxChar(TJSONProtocol.java:322)
    at org.apache.thrift.protocol.TJSONProtocol.readJSONInteger(TJSONProtocol.java:698)
    at org.apache.thrift.protocol.TJSONProtocol.readFieldBegin(TJSONProtocol.java:837)
    at com.vanilla.thrift.example.entities.StudentThriftObject$StudentThriftObjectStandardScheme.read(StudentThriftObject.java:486)
    at com.vanilla.thrift.example.entities.StudentThriftObject$StudentThriftObjectStandardScheme.read(StudentThriftObject.java:479)
    at com.vanilla.thrift.example.entities.StudentThriftObject.read(StudentThriftObject.java:413)
    at com.vanilla.thrift.controller.Main.main(Main.java:24)
Run Code Online (Sandbox Code Playgroud)

我错过了什么吗?

java json thrift thrift-protocol

5
推荐指数
1
解决办法
1万
查看次数

用C++创建二进制(自定义长度)字符串

我正在使用Apache Thrift RPC(Compiled to C++)机制与Apache Flume进行通信.我必须使用此平台提供的特定API.
我想发送二进制数据,但RPC函数只接受std :: string作为参数.因此,我只能发送第一次出现0x00之前的二进制数据.

u_char bin[10] = {'a','b',1,'d','e',0,'2','3','4','5'};
// Takes only the first 5 bytes, and sets a length of 5
string art_test((const char *)bin);
Run Code Online (Sandbox Code Playgroud)

我搜索了源代码,我调用的函数将str.data()转换为(uint8_t*)并发送长度为str.size()的数据.

uint32_t ssize = static_cast<uint32_t>(str.size());
trans_->write((uint8_t*)str.data(), ssize);
Run Code Online (Sandbox Code Playgroud)

有没有办法创建一个'二进制字符串',uint8_t作为数据并具有指定的长度?甚至可能用所需的二进制数据创建我自己的字符串的内存表示.

c++ thrift thrift-protocol c++11

5
推荐指数
0
解决办法
70
查看次数

cassandra ::我可以创建没有主键的表吗?

现在我正在学习Cassandra,所以我得到了一个没有主键的表。但是它有一些索引。

所以这是我的疑问,我可以创建没有主键的表吗?

CREATE TABLE subscription (subscriberid varchar,productid varchar,panaccessproductid varchar,operatorproductid varchar,price float,fallback varchar,paymenttype varchar,operatorid varchar,subscriptiontype varchar,expiry timestamp,subscriptionstatus varchar,created timestamp);
Run Code Online (Sandbox Code Playgroud)

没有主键,subscriberid,productid,operatorid和subscriptiontype是索引。这可能吗?

从文档中

首要的关键::主键标识数据存储的位置和顺序。主键是在表创建时定义的,不能更改。如果必须更改主键,则会创建一个新的表架构,并将数据写入新表。Cassandra是分区行存储,主键(分区键)的组件标识哪个节点将保存特定的表行。主键至少必须包含一个分区键。复合分区键可以拆分数据集,以便将相关数据存储在单独的分区中。复合主键包括聚类列,这些列对分区上的数据进行排序。在Cassandra中,表主键的定义至关重要。在选择哪些列定义主键之前,请仔细建模将如何插入和检索表中的数据。分区的大小,分区中数据的顺序,分区在群集节点之间的分布-所有这些考虑因素决定了为表选择最佳主键。

cql cassandra nosql thrift-protocol cqlsh

5
推荐指数
1
解决办法
5347
查看次数

如何使用pyspark将spark与hive连接?

我正在尝试使用pyspark, 远程读取配置单元表。它指出无法连接到 Hive Metastore 客户端的错误。

我在 SO 和其他来源上阅读了多个答案,它们主要是配置,但没有一个可以解决为什么我无法远程连接的问题。我阅读了文档并观察到无需更改任何配置文件,我们就可以将 spark 与hive. 注意:我已经端口转发了一台hive正在运行的机器并将其提供给localhost:10000. 我什至使用相同的方法连接presto并且能够在hive.

代码是:

from pyspark import SparkContext, SparkConf
from pyspark.sql import SparkSession, HiveContext
SparkContext.setSystemProperty("hive.metastore.uris", "thrift://localhost:9083")
sparkSession = (SparkSession
                .builder
                .appName('example-pyspark-read-and-write-from-hive')
                .enableHiveSupport()
                .getOrCreate())
data = [('First', 1), ('Second', 2), ('Third', 3), ('Fourth', 4), ('Fifth', 5)]
df = sparkSession.createDataFrame(data)
df.write.saveAsTable('example')

Run Code Online (Sandbox Code Playgroud)

我希望输出是表被保存的确认,但相反,我正面临这个错误。

抽象错误是:

During handling of the above exception, another exception occurred:

Traceback (most recent call last): …
Run Code Online (Sandbox Code Playgroud)

hive thrift-protocol python-3.x pyspark pyspark-sql

5
推荐指数
1
解决办法
1万
查看次数

在邮件中存档大文件

我正在使用thrift for tcp二进制协议,用于发送和读取文件(最大大小为64MB).节俭有能力吗?

我以为使用过:

struct SomeMessage {
 1: byte data
}
Run Code Online (Sandbox Code Playgroud)

节俭有多高效?编组/解编/通过电汇发送?

thrift thrift-protocol

4
推荐指数
1
解决办法
2430
查看次数

尝试使用thrift的TFileTransport和TFileProcessor让Python客户端与Java服务器通信

我正在尝试使用thrift的TFileTransport包装要从Python调用的Java类.我尝试使用两个协议TJSON和TBinary,但我一直得到这个例外

org.apache.thrift.transport.TTransportException: FileTransport error: bad event size
    at org.apache.thrift.transport.TFileTransport.readEvent(TFileTransport.java:327)
    at org.apache.thrift.transport.TFileTransport.read(TFileTransport.java:468)
    at org.apache.thrift.transport.TFileTransport.readAll(TFileTransport.java:439)
    at org.apache.thrift.protocol.TJSONProtocol$LookaheadReader.read(TJSONProtocol.java:263)
    at org.apache.thrift.protocol.TJSONProtocol.readJSONSyntaxChar(TJSONProtocol.java:320)
    at org.apache.thrift.protocol.TJSONProtocol.readJSONArrayStart(TJSONProtocol.java:784)
    at org.apache.thrift.protocol.TJSONProtocol.readMessageBegin(TJSONProtocol.java:795)
    at org.apache.thrift.TBaseProcessor.process(TBaseProcessor.java:27)
    at org.apache.thrift.transport.TFileProcessor.processUntil(TFileProcessor.java:69)
    at org.apache.thrift.transport.TFileProcessor.processChunk(TFileProcessor.java:102)
    at org.apache.thrift.transport.TFileProcessor.processChunk(TFileProcessor.java:111)
    at org.apache.thrift.transport.TFileProcessor.processChunk(TFileProcessor.java:118)
    at com.netflix.suro.client.SendToPyServer.startThriftServer(SendToPyServer.java:51)
    at com.netflix.suro.client.SendToPyServer.main(SendToPyServer.java:67)
Run Code Online (Sandbox Code Playgroud)

这就是我的Python客户端的外观:

 def __init__(self):
        self.outFile=open("../../ThriftFile.in","a")
        self.transport = TTransport.TFileObjectTransport(self.outFile)
        self.protocol = TJSONProtocol.TJSONProtocol(self.transport)
        self.client = sendPyInterface.Client(self.protocol)
        self.transport.open()

    def send(self,routingKey, message):
        self.transport.write(pickle.dumps(self.client.send_send(routingKey, message))) 


    def configClient(self,configurationDict):       
        self.transport.write(pickle.dumps(self.client.send_ClientConfig(configurationDict)))    

if __name__ == "__main__":
    SuroClient=SuroPyClient()
    configurationDict={"ClientConfig.LB_TYPE":"static","ClientConfig.LB_SERVER":"localhost:7101"}
    SuroClient.configClient(configurationDict)
    SuroClient.send("routingKey", "testMessage")
Run Code Online (Sandbox Code Playgroud)

这是我的服务器:

public static void startThriftServer(SendPyInterface.Processor processor) {
            try {
                File input = new File("src/main/java/com/netflix/suro/client/ThriftFile.in"); …
Run Code Online (Sandbox Code Playgroud)

python java thrift thrift-protocol

4
推荐指数
1
解决办法
870
查看次数

可以从现有的java/scala接口和数据类型生成.thrift文件吗?

是否有一种简单的方法来获取现有的Java/scala数据类型和API接口并生成相应的.thrift文件?Thrift生成服务器数据结构是过度侵入的,因为它会产生后果:

  • 我无法注释我的数据结构(例如,XML,JSON,hibernate持久性......)
  • 此模式与其他想要拥有或需要修改源文件的序列化框架冲突.

其结果是,它似乎是节俭的力量本身将其用于我的服务器专属持久格式 - 除非,那就是,我创建一个围绕节俭或与这些数据结构处理(休眠其他我的坚持格式数据编组包装,杰克逊,斯卡拉BeanProperty,...).然而,这违背了自动数据编组工具如节俭的目的,并且直接导致具有保持相同,但是,单独的接口和数据结构(的天才的工程师时间和精力=废物)的容易出错的世界.

我对Thrift自动生成客户端代码非常满意.但是,我(强烈)认为我需要自由编辑我的服务器在API中处理的数据结构.

java scala thrift thrift-protocol

4
推荐指数
1
解决办法
1921
查看次数

Spray是否有Thrift marshaling/unmarshaling支持?

我的组织选择采用Thrift消息传递作为整合客户和服务的通用语言.我们所有的服务都是用Scala编写的(或将被编写),而我们的客户端则是用其他语言编写的.

目前(据我所知)Scrooge是Scala唯一的Thrift IDL编译器,它以Finagle为目标.我想选择在Spray上构建服务.

如果有的话,我可以选择使用现成的(开源)软件吗?

scala thrift thrift-protocol spray

3
推荐指数
1
解决办法
753
查看次数