-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4f260e0
commit 1c046fb
Showing
5 changed files
with
45 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from thrift.transport import TSocket | ||
from thrift.transport import TTransport | ||
from thrift.protocol import TBinaryProtocol | ||
from gen_py.timestamp_service import TimestampService | ||
|
||
|
||
class ThriftTimestampClient: | ||
"""Thrift client to fetch the current timestamp from the Thrift server.""" | ||
def __init__(self, host='localhost', port=9090): | ||
"""Initialize the Thrift client with the host and port of the Thrift server.""" | ||
self.host = host | ||
self.port = port | ||
|
||
def get_current_timestamp(self): | ||
"""Fetch the current timestamp from the Thrift server.""" | ||
try: | ||
transport = TSocket.TSocket(self.host, self.port) | ||
transport = TTransport.TBufferedTransport(transport) | ||
protocol = TBinaryProtocol.TBinaryProtocol(transport) | ||
client = TimestampService.Client(protocol) | ||
transport.open() | ||
timestamp = client.getCurrentTimestamp() | ||
transport.close() | ||
return timestamp | ||
|
||
except Exception as e: | ||
print("An error occurred while fetching the timestamp:", e) | ||
return None |
Binary file not shown.