Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
ipgallery.common.java
/
microservice
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Registry
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
9f4fc38e
authored
May 23, 2017
by
amir
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
before testing server zmq
parent
f8be7949
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
191 additions
and
19 deletions
src/main/java/microservice/services/IRestServiceZmqImpl.java
src/main/java/microservice/services/protocol/zmq/RestImpl.java
src/test/java/microservice/TestServicesAndMethods.java
src/test/java/microservice/TestZMQ.java
src/main/java/microservice/services/IRestServiceZmqImpl.java
View file @
9f4fc38e
This diff is collapsed.
Click to expand it.
src/main/java/microservice/services/protocol/zmq/RestImpl.java
View file @
9f4fc38e
...
...
@@ -3,7 +3,13 @@ package microservice.services.protocol.zmq;
import
microservice.common.context.RestMsg
;
import
microservice.io.iface.IRequest
;
import
microservice.io.iface.IResponse
;
import
microservice.services.IRestServiceZmqImpl
;
import
microservice.utils.ZSocketPool
;
import
org.apache.commons.lang.SerializationUtils
;
import
org.zeromq.ZMQ
;
import
org.zeromq.ZSocket
;
import
java.io.ByteArrayInputStream
;
import
java.io.InputStream
;
import
java.nio.ByteBuffer
;
import
java.util.List
;
...
...
@@ -22,17 +28,17 @@ public class RestImpl {
@Override
public
InputStream
getInputStream
()
{
return
n
ull
;
return
n
ew
ByteArrayInputStream
(
restMsg
.
content
().
getBytes
())
;
}
@Override
public
String
getQueryString
()
{
return
null
;
return
restMsg
.
queryString
()
;
}
@Override
public
String
getRelativePath
()
{
return
null
;
return
restMsg
.
url
()
;
}
@Override
...
...
@@ -47,25 +53,39 @@ public class RestImpl {
@Override
public
boolean
startAsync
(
Runnable
asyncFunc
)
{
return
fals
e
;
return
tru
e
;
}
}
public
static
class
IResponseZmqRestImpl
implements
IResponse
{
RestMsg
restMsg
=
null
;
public
IResponseZmqRestImpl
(
RestMsg
restMsg
)
{
this
.
restMsg
=
restMsg
;
ZSocketPool
serverSendPool
=
null
;
long
rcid
=
0
;
public
IResponseZmqRestImpl
(
RestMsg
restMsg
,
ZSocketPool
serverSendPool
,
long
rcid
)
{
this
.
restMsg
=
restMsg
;
this
.
serverSendPool
=
serverSendPool
;
this
.
rcid
=
rcid
;
}
@Override
public
void
send
(
ByteBuffer
buffer
)
{
send
(
new
String
(
buffer
.
array
()));
}
@Override
public
void
send
(
String
response
)
{
ZSocket
socket
=
null
;
try
{
byte
[]
data
=
SerializationUtils
.
serialize
(
new
IRestServiceZmqImpl
.
ServerReplyMsg
(
rcid
,
restMsg
.
source
(),
response
));
socket
=
serverSendPool
.
borrowObject
();
socket
.
send
(
data
,
ZMQ
.
DONTWAIT
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
if
(
socket
!=
null
)
serverSendPool
.
returnObject
(
socket
);
}
}
}
}
\ No newline at end of file
src/test/java/microservice/TestServicesAndMethods.java
View file @
9f4fc38e
...
...
@@ -5,6 +5,8 @@ import com.google.common.cache.CacheBuilder;
import
io.undertow.predicate.Predicate
;
import
io.undertow.util.PathTemplateMatcher
;
import
microservice.services.CommonServices
;
import
microservice.services.IRestServiceZmqImpl
;
import
org.apache.commons.lang.SerializationUtils
;
import
org.junit.Test
;
import
java.util.Arrays
;
...
...
@@ -181,4 +183,5 @@ public class TestServicesAndMethods {
System
.
out
.
println
(
"Remove gcache Test of: "
+
String
.
valueOf
(
ITERATIONS
)
+
" took (msec): "
+
String
.
valueOf
(
System
.
currentTimeMillis
()
-
start
));
}
}
src/test/java/microservice/TestZMQ.java
View file @
9f4fc38e
...
...
@@ -6,6 +6,8 @@ import itc.ItcMessageQueue;
import
microservice.common.context.CrudMethod
;
import
microservice.common.context.RestMsg
;
import
microservice.common.context.RestResponse
;
import
microservice.services.IRestServiceZmqImpl
;
import
org.apache.commons.lang.SerializationUtils
;
import
org.junit.Test
;
import
org.zeromq.*
;
import
rx.Observable
;
...
...
@@ -406,4 +408,13 @@ public class TestZMQ {
}
@Test
public
void
testSerialize
(){
byte
[]
data
=
SerializationUtils
.
serialize
(
new
IRestServiceZmqImpl
.
ServerReplyMsg
(
2
,
SOURCE_CHANNEL
,
JSON_CONTENT
));
IRestServiceZmqImpl
.
ServerReplyMsg
serverReplyMsg
=
(
IRestServiceZmqImpl
.
ServerReplyMsg
)
SerializationUtils
.
deserialize
(
data
);
System
.
out
.
println
(
serverReplyMsg
.
getReplyAddress
());
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment