File tree 7 files changed +124
-1
lines changed
7 files changed +124
-1
lines changed Original file line number Diff line number Diff line change
1
+ name : Build and Release
2
+
3
+ on :
4
+ push :
5
+ tags :
6
+ - ' v*'
7
+
8
+ jobs :
9
+ build-linux :
10
+ runs-on : ubuntu-latest
11
+
12
+ steps :
13
+ - uses : actions/checkout@v3
14
+
15
+ - name : Install Rust
16
+ uses : actions-rs/toolchain@v1
17
+ with :
18
+ toolchain : stable
19
+ target : x86_64-unknown-linux-gnu
20
+ override : true
21
+
22
+ - name : Build
23
+ run : |
24
+ cargo build --release --target x86_64-unknown-linux-gnu
25
+ tar -czf anypay-websockets-linux-x86_64.tar.gz -C target/x86_64-unknown-linux-gnu/release anypay-websockets
26
+
27
+ - name : Create Release
28
+ uses : softprops/action-gh-release@v1
29
+ if : startsWith(github.ref, 'refs/tags/')
30
+ with :
31
+ files : |
32
+ anypay-websockets-linux-x86_64.tar.gz
33
+ env :
34
+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
35
+
36
+ - name : Upload artifact
37
+ uses : actions/upload-artifact@v3
38
+ with :
39
+ name : anypay-websockets-linux-x86_64
40
+ path : target/x86_64-unknown-linux-gnu/release/anypay-websockets
Original file line number Diff line number Diff line change @@ -25,4 +25,14 @@ shortid = "1.0.6"
25
25
bigdecimal = " 0.4.7"
26
26
anyhow = " 1.0"
27
27
alloy = { version = " 0.3" , features = [" full" ] }
28
- futures-util = " 0.3"
28
+ futures-util = " 0.3"
29
+
30
+ [profile .release ]
31
+ opt-level = 3
32
+ lto = true
33
+ codegen-units = 1
34
+ panic = ' abort'
35
+ strip = true # Automatically strip symbols from the binary
36
+
37
+ [target .x86_64-unknown-linux-gnu ]
38
+ linker = " x86_64-unknown-linux-gnu-gcc"
Original file line number Diff line number Diff line change @@ -105,6 +105,15 @@ channels:
105
105
publish :
106
106
message :
107
107
oneOf :
108
+ - name : Ping
109
+ payload :
110
+ type : object
111
+ required :
112
+ - type
113
+ properties :
114
+ type :
115
+ type : string
116
+ const : Ping
108
117
- name : CreateInvoice
109
118
payload :
110
119
type : object
@@ -132,6 +141,19 @@ channels:
132
141
subscribe :
133
142
message :
134
143
oneOf :
144
+ - name : Pong
145
+ payload :
146
+ type : object
147
+ properties :
148
+ type :
149
+ type : string
150
+ const : pong
151
+ status :
152
+ type : string
153
+ enum : [success]
154
+ timestamp :
155
+ type : integer
156
+ format : int64
135
157
- name : Response
136
158
payload :
137
159
oneOf :
Original file line number Diff line number Diff line change
1
+ import os
2
+ import asyncio
3
+ import websockets
4
+ import json
5
+ from datetime import datetime
6
+
7
+ async def test_ping ():
8
+ try :
9
+ # Connect to WebSocket server
10
+ async with websockets .connect ('ws://localhost:8080' ) as websocket :
11
+ # Create ping message
12
+ ping_message = {
13
+ "action" : "ping"
14
+ }
15
+
16
+ print ("Sending ping..." )
17
+ await websocket .send (json .dumps (ping_message ))
18
+
19
+ # Wait for pong response
20
+ response = await websocket .recv ()
21
+ response_data = json .loads (response )
22
+
23
+ print (f"Received response: { response_data } " )
24
+
25
+ # Validate response
26
+ if (response_data .get ('type' ) == 'pong' and
27
+ response_data .get ('status' ) == 'success' and
28
+ 'timestamp' in response_data ):
29
+
30
+ # Convert timestamp to readable format
31
+ timestamp = datetime .fromtimestamp (response_data ['timestamp' ])
32
+ print (f"✅ Received pong at { timestamp } " )
33
+ print (f"Round trip latency: { datetime .utcnow ().timestamp () - response_data ['timestamp' ]} s" )
34
+ else :
35
+ print ("❌ Invalid pong response:" , response_data )
36
+
37
+ except Exception as e :
38
+ print (f"❌ Error: { e } " )
39
+
40
+ if __name__ == "__main__" :
41
+ asyncio .run (test_ping ())
Original file line number Diff line number Diff line change @@ -203,6 +203,7 @@ async fn consume_events(mut consumer: Consumer) {
203
203
while let Some ( delivery) = consumer. next ( ) . await {
204
204
if let Ok ( delivery) = delivery {
205
205
if let Ok ( data) = std:: str:: from_utf8 ( & delivery. data ) {
206
+ println ! ( "AMQP Event: {}" , data) ;
206
207
tracing:: info!( "AMQP Event: {}" , data) ;
207
208
}
208
209
delivery. ack ( BasicAckOptions :: default ( ) ) . await . ok ( ) ;
Original file line number Diff line number Diff line change @@ -178,6 +178,13 @@ impl AnypayEventsServer {
178
178
} )
179
179
}
180
180
}
181
+ Message :: Ping => {
182
+ json ! ( {
183
+ "type" : "pong" ,
184
+ "status" : "success" ,
185
+ "timestamp" : chrono:: Utc :: now( ) . timestamp( )
186
+ } )
187
+ } ,
181
188
}
182
189
}
183
190
Original file line number Diff line number Diff line change @@ -45,6 +45,8 @@ pub enum Message {
45
45
CancelInvoice {
46
46
uid : String ,
47
47
} ,
48
+ #[ serde( rename = "ping" ) ]
49
+ Ping ,
48
50
}
49
51
50
52
fn deserialize_number_from_string < ' de , D > ( deserializer : D ) -> Result < f64 , D :: Error >
You can’t perform that action at this time.
0 commit comments