![]() ![]() See these two ways, We gave up all of a sudden, I just wanted to add a monitor, I didn't want to change too much, If you want to see such a monitor, That big change, Fear of affecting the business ( We are api The service is still used by many business parties ). Re inherit TFramedTransport Class override a method in it. modify thrift The framework source code, 2. Only then did I find out, our thrift The way the interface is provided is different from what is said on the Internet, And in our case, If you need to get Client Ip, There are several ways :1. After a few tries, I can't find it, So I found it on the Internet according to this mistake ,TFramedTransport obtain IP( This misdescription refers to : ). I just found that the actual instantiated class is not TSocket type. In limine, I thought my writing was wrong, Check the blog on the Internet. Say TFramedTransport Can't be converted into TSocket This class, It is estimated that the instance class is inconsistent with the class to be transferred. TFramedTransport cannot be cast to .TSocket ![]() However, When we actually do it, Built this monitor class, Set up their own local service, And unit testing, I found the following error. Reference resources : There are two ways to get Thrift The calling client IP Address (socket.getSocket().getRemoteSocketAddress()) TSocket socket = (TSocket)inputTransport * hold TTransport Object conversion to TSocket, And then in TSocket Get in there Socket, You can get the client IP ( It's possible to transform the unsuccessful ,inputTransport Not necessarily for TSocket Class, It's also possible for TFrmef, It depends on thrift The way services are provided ) Public void processContext(ServerContext serverContext, TTransport inputTransport, TTransport outputTransport) * Every time a method is called, It will trigger once And then we're going to do something about it thrift The part of the interface, I thought it was all interfaces, It is estimated that thrift The framework also provides a corresponding way to get ( We use the native apche thrift Framework to provide services ), So I found it on the Internet, Find out thrift The interface doesn't seem to http The interface is so good, It's said on the Internet that we need to add a monitoring class, Monitor requests, Similar to the following : /** I thought there would be no problem, But when we're ready to start transforming, Find out http The interface provided by the protocol, Better transformation, direct httpRequest You can get the client ip, The request parameters are also easy to print. Specific operation method Method 1, Modify the business code directlyĪt the beginning, we wanted to modify the original business code, Plus call ip And the log of the request parameter is printed. One of our api Service invocation can be divided into thrift Calls and http call, Because the old service design before was relatively simple, Don't pass dubbo Call the registry, And there's no complete monitoring ( Don't ask me why I didn't, I have no choice ), Cause I want to find the call ip I can't find, There is no record in the log. Lately, I do such a thing in the company, Sort out the old api service, We need to count each request of the interface ip And request parameters, Find the corresponding call ip, So as to inform the business party to change it to a new one api service. And there's a lot of demand recently, I'm busy at work, At the same time, I met a more troublesome demand, Just want to record, Let's start with this week's article. As usual, let's talk about the recent situation first, It's just the new year ? See a lot of people writing the annual summary, So I'm also writing the annual summary ( In fact, I haven't written about it before, I feel a little bit this year, Also want to record ), It turns out that it's a little bit too much, I wanted to send it before New Year's day, After new year's Day, Today I'm still writing, And I can't finish it, But that's about it, It's expected to come out tomorrow. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |