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
345582f7
authored
Jan 01, 2020
by
Amir Aharon
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
add create public namespace and tests
parent
3d5bed43
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
40 additions
and
9 deletions
src/main/java/microservice/params/PulsarParams.java
src/main/java/microservice/services/IPubSubServicePulsarImpl.java
src/main/java/microservice/utils/ServiceBuilderFactory.java
src/test/java/microservice/TestLogger.java
src/test/java/microservice/TestMicroserviceApp.java
src/test/java/microservice/TestServicesAndMethods.java
src/main/java/microservice/params/PulsarParams.java
View file @
345582f7
...
...
@@ -12,7 +12,7 @@ public class PulsarParams {
String
serviceUrl
;
String
adminUrl
;
int
consumersThreadPoolSize
;
boolean
createPublicNamespace
;
public
static
class
PulsarParamsBuilder
{
public
static
final
int
DEFAULT_ADMIN_PORT
=
8080
;
...
...
@@ -23,6 +23,7 @@ public class PulsarParams {
String
serviceUrl
;
String
adminUrl
=
null
;
int
consumersThreadPoolSize
=
0
;
boolean
createPublicNamespace
=
false
;
public
PulsarParamsBuilder
()
{
}
...
...
@@ -62,6 +63,11 @@ public class PulsarParams {
this
.
consumersThreadPoolSize
=
consumersThreadPoolSize
;
}
public
PulsarParamsBuilder
setCreatePublicNamespace
(
boolean
createPublicNamespace
)
{
this
.
createPublicNamespace
=
createPublicNamespace
;
return
this
;
}
public
PulsarParams
build
(){
try
{
if
(
adminUrl
==
null
)
{
...
...
@@ -75,7 +81,8 @@ public class PulsarParams {
clusters
,
serviceUrl
,
adminUrl
,
consumersThreadPoolSize
);
consumersThreadPoolSize
,
createPublicNamespace
);
}
catch
(
Exception
e
){
System
.
err
.
println
(
"PulsarParamsBuilder > "
+
e
.
toString
());
}
...
...
@@ -83,12 +90,13 @@ public class PulsarParams {
}
}
public
PulsarParams
(
int
msgTtl
,
String
clusters
,
String
serviceUrl
,
String
adminUrl
,
int
consumersThreadPoolSize
)
{
public
PulsarParams
(
int
msgTtl
,
String
clusters
,
String
serviceUrl
,
String
adminUrl
,
int
consumersThreadPoolSize
,
boolean
createPublicNamespace
)
{
this
.
msgTtl
=
msgTtl
;
this
.
clusters
=
clusters
;
this
.
serviceUrl
=
serviceUrl
;
this
.
adminUrl
=
adminUrl
;
this
.
consumersThreadPoolSize
=
consumersThreadPoolSize
;
this
.
createPublicNamespace
=
createPublicNamespace
;
}
public
int
getMsgTtl
()
{
...
...
@@ -130,4 +138,8 @@ public class PulsarParams {
public
void
setConsumersThreadPoolSize
(
int
consumersThreadPoolSize
)
{
this
.
consumersThreadPoolSize
=
consumersThreadPoolSize
;
}
public
boolean
isCreatePublicNamespace
()
{
return
createPublicNamespace
;
}
}
src/main/java/microservice/services/IPubSubServicePulsarImpl.java
View file @
345582f7
...
...
@@ -35,7 +35,7 @@ import java.util.regex.Pattern;
* the part after the service name contains the method path to pass to the reactor
* the consumer part receives a message, creates the pubsub context and dispatch it to
* thread poll executor which handle the message and delegate it to the reactor
* currently
ot sending message as a flatbuffer, using json so that external tools
* currently
n
ot sending message as a flatbuffer, using json so that external tools
* i.e apache flink, can subscribe and inject the messages as well.
*/
public
class
IPubSubServicePulsarImpl
extends
CommonServices
.
IPubSubService
{
...
...
@@ -44,6 +44,7 @@ public class IPubSubServicePulsarImpl extends CommonServices.IPubSubService {
public
static
final
String
SERVICE_NAME
=
"IPubSubServicePulsarImpl"
;
public
static
final
String
PERSISTENT_PREFIX
=
"persistent://"
;
public
static
final
String
TOPIC_PREFIX
=
PERSISTENT_PREFIX
+
Constants
.
DEFAULT_TENANT
;
public
static
final
String
PUBLIC_NAMESPACE
=
"public"
;
public
static
int
INIITIAL_PRODUCERS_SIZE
=
5
;
private
String
adminUrl
;
private
PulsarClient
client
=
null
;
...
...
@@ -105,6 +106,11 @@ public class IPubSubServicePulsarImpl extends CommonServices.IPubSubService {
createConsumer
();
break
;
}
// check for public namespace
if
(
pulsarParams
.
isCreatePublicNamespace
())
{
adminValidateTenantAndNamespace
(
Constants
.
DEFAULT_TENANT
,
PUBLIC_NAMESPACE
);
}
}
catch
(
PulsarClientException
e
)
{
System
.
err
.
println
(
e
.
toString
());
return
false
;
...
...
src/main/java/microservice/utils/ServiceBuilderFactory.java
View file @
345582f7
...
...
@@ -355,6 +355,16 @@ public class ServiceBuilderFactory {
return
this
;
}
/**
* msgs published to all services has 'public' namespace
* @param createPublicNamespace
* @return
*/
public
PubSubServicePulsarBuilder
setCreatePublicNamespace
(
boolean
createPublicNamespace
)
{
this
.
pulsarParamsBuilder
.
setCreatePublicNamespace
(
createPublicNamespace
);
return
this
;
}
private
boolean
validateParams
()
{
if
(
pulsarParamsBuilder
.
getServiceUrl
()
==
null
)
return
false
;
...
...
src/test/java/microservice/TestLogger.java
View file @
345582f7
package
microservice
;
import
microservice.io.iface.ILogger
;
import
common.microservice.io.iface.ILogger
;
import
microservice.io.impl.ILoggerConsoleImpl
;
import
org.junit.Test
;
...
...
src/test/java/microservice/TestMicroserviceApp.java
View file @
345582f7
...
...
@@ -85,7 +85,7 @@ public class TestMicroserviceApp {
System
.
setProperty
(
"configFile.location"
,
"/opt/mcx/config/config.properties"
);
System
.
setProperty
(
"influxdb.hostport"
,
"172.16.1.244:8086"
);
String
appName
=
"
testApp
"
;
String
appName
=
"
activities
"
;
/**
* creating the services
*/
...
...
@@ -184,7 +184,7 @@ public class TestMicroserviceApp {
ObjectMapper
objectMapper
=
new
ObjectMapper
();
private
void
testPubSubMsg
(
CommonServices
.
IPubSubService
.
PubSubMsgContext
msgCtx
)
{
//
System.out.println("Recieved mcid: " + msgCtx.getMcid());
System
.
out
.
println
(
"Recieved mcid: "
+
msgCtx
.
getMcid
());
try
{
JsonNode
jsonNode
=
objectMapper
.
readValue
(
msgCtx
.
getMsg
(),
JsonNode
.
class
);
handleJsonTestStartStop
(
jsonNode
);
...
...
src/test/java/microservice/TestServicesAndMethods.java
View file @
345582f7
...
...
@@ -281,11 +281,13 @@ public class TestServicesAndMethods {
CommonServices
.
IService
iService
=
ServiceBuilderFactory
.
createPubSubServicePulsarBuilder
(
CommonServices
.
EnumPubSubServiceMode
.
E_PUBLISHER
)
.
setServiceUrl
(
"localhost:6650"
)
.
setAdminUrl
(
"localhost:8080"
)
// .setCreatePublicNamespace(true)
.
build
();
CommonServices
.
IPubSubService
pubSubService
=
(
CommonServices
.
IPubSubService
)
iService
;
pubSubService
.
init
();
pubSubService
.
run
();
String
topic
=
"/testApp/activity"
;
// '[domain]/[method]'
//String topic = "/testApp/activity"; // '[domain]/[method]'
String
topic
=
"/activities/activity"
;
// '[domain]/[method]'
ObjectNode
objectNode
=
JsonNodeFactory
.
instance
.
objectNode
().
put
(
"state"
,
"start"
).
put
(
"iterations"
,
ITERATIONS
);
System
.
out
.
println
(
"Testing "
+
String
.
valueOf
(
ITERATIONS
)
+
" iterations"
);
long
start
=
System
.
currentTimeMillis
();
...
...
@@ -298,7 +300,7 @@ public class TestServicesAndMethods {
objectNode
.
put
(
"state"
,
"end"
);
pubSubService
.
publish
(
new
CommonServices
.
IPubSubService
.
PubSubMsgContext
(
topic
,
objectNode
.
toString
()));
System
.
out
.
println
(
"Async publish Test of: "
+
String
.
valueOf
(
ITERATIONS
)
+
" took (msec): "
+
String
.
valueOf
(
System
.
currentTimeMillis
()
-
start
));
Thread
.
sleep
(
1000
);
Thread
.
sleep
(
1000
0
);
pubSubService
.
shutdown
();
}
}
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