Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
streamingUserPortrait
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
赵威
streamingUserPortrait
Commits
db6097cd
Commit
db6097cd
authored
Feb 05, 2021
by
赵威
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
get request
parent
507ceb30
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
56 additions
and
14 deletions
+56
-14
build.sbt
build.sbt
+2
-1
Main.scala
src/main/scala/com.gmei.up/Main.scala
+9
-4
Content.scala
src/main/scala/com.gmei.up/utils/Content.scala
+3
-0
ES.scala
src/main/scala/com.gmei.up/utils/ES.scala
+18
-9
Redis.scala
src/main/scala/com.gmei.up/utils/Redis.scala
+24
-0
No files found.
build.sbt
View file @
db6097cd
...
@@ -36,10 +36,11 @@ lazy val root = (project in file("."))
...
@@ -36,10 +36,11 @@ lazy val root = (project in file("."))
libraryDependencies
+=
jsonNative
,
libraryDependencies
+=
jsonNative
,
libraryDependencies
+=
jsonJackson
,
libraryDependencies
+=
jsonJackson
,
//libraryDependencies += "com.sksamuel.elastic4s" %% "elastic4s-http" % "6.7.8",
libraryDependencies
+=
esCore
,
libraryDependencies
+=
esCore
,
libraryDependencies
+=
esJava
,
libraryDependencies
+=
esJava
,
libraryDependencies
+=
"net.debasishg"
%%
"redisclient"
%
"3.30"
,
libraryDependencies
+=
flinkCore
,
libraryDependencies
+=
flinkCore
,
libraryDependencies
+=
flinkScala
,
libraryDependencies
+=
flinkScala
,
libraryDependencies
+=
flinkStreamingScala
,
libraryDependencies
+=
flinkStreamingScala
,
...
...
src/main/scala/com.gmei.up/Main.scala
View file @
db6097cd
...
@@ -11,7 +11,7 @@ import org.apache.flink.streaming.connectors.kafka.{
...
@@ -11,7 +11,7 @@ import org.apache.flink.streaming.connectors.kafka.{
import
org.apache.flink.api.common.typeinfo.
{
TypeHint
,
TypeInformation
,
Types
}
import
org.apache.flink.api.common.typeinfo.
{
TypeHint
,
TypeInformation
,
Types
}
import
org.apache.kafka.clients.consumer.ConsumerRecord
import
org.apache.kafka.clients.consumer.ConsumerRecord
import
com.alibaba.fastjson.JSON
import
com.alibaba.fastjson.JSON
import
com.gmei.up.utils.
{
UserInfo
,
ES
}
import
com.gmei.up.utils.
{
UserInfo
,
ES
,
Redis
}
class
UserInfoDeserializationSchema
extends
KafkaDeserializationSchema
[
UserInfo
]
{
class
UserInfoDeserializationSchema
extends
KafkaDeserializationSchema
[
UserInfo
]
{
override
def
isEndOfStream
(
t
:
UserInfo
)
:
Boolean
=
false
override
def
isEndOfStream
(
t
:
UserInfo
)
:
Boolean
=
false
...
@@ -55,17 +55,22 @@ object Main {
...
@@ -55,17 +55,22 @@ object Main {
val
projects
=
user
.
projects
.
toList
val
projects
=
user
.
projects
.
toList
val
secondDemands
=
user
.
secondDemands
.
toList
val
secondDemands
=
user
.
secondDemands
.
toList
val
cityId
=
user
.
cityId
val
cityId
=
user
.
cityId
println
(
user
.
deviceId
)
val
deviceId
=
user
.
deviceId
println
(
deviceId
)
println
(
projects
.
mkString
(
" "
))
println
(
projects
.
mkString
(
" "
))
val
diaryReq
=
ES
.
generateDiaryRequest
(
projects
,
secondDemands
,
cityId
)
val
diaryReq
=
ES
.
generateDiaryRequest
(
projects
,
secondDemands
,
cityId
)
val
tractateReq
=
ES
.
generateTractateRequest
(
projects
,
secondDemands
)
val
tractateReq
=
ES
.
generateTractateRequest
(
projects
,
secondDemands
)
val
answerReq
=
ES
.
generateAnswerRequest
(
projects
,
secondDemands
)
val
answerReq
=
ES
.
generateAnswerRequest
(
projects
,
secondDemands
)
val
serviceDiaryReq
=
ES
.
generateServiceDiaryRequest
(
projects
,
secondDemands
,
cityId
)
val
serviceDiaryReq
=
ES
.
generateServiceDiaryRequest
(
projects
,
secondDemands
,
cityId
)
ES
.
test
(
diaryReq
,
tractateReq
,
answerReq
,
serviceDiaryReq
)
val
a
=
ES
.
request
(
diaryReq
)
Redis
.
save
(
ES
.
request
(
diaryReq
),
deviceId
,
"diary"
)
// ES.test(diaryReq, tractateReq, answerReq, serviceDiaryReq)
println
(
"########################"
)
println
(
"########################"
)
user
.
deviceId
deviceId
}
}
// stream.print
// stream.print
...
...
src/main/scala/com.gmei.up/utils/Content.scala
0 → 100644
View file @
db6097cd
package
com.gmei.up.utils
case
class
Content
(
id
:
String
,
index
:
String
,
projects
:
String
)
src/main/scala/com.gmei.up/utils/ES.scala
View file @
db6097cd
...
@@ -2,6 +2,8 @@ package com.gmei.up.utils
...
@@ -2,6 +2,8 @@ package com.gmei.up.utils
import
scala.collection.mutable.ListBuffer
import
scala.collection.mutable.ListBuffer
import
scala.util.Try
import
scala.util.Try
import
scala.concurrent.Future
import
scala.concurrent.ExecutionContext.global
import
org.json4s.JsonDSL._
import
org.json4s.JsonDSL._
import
org.json4s.jackson.JsonMethods._
import
org.json4s.jackson.JsonMethods._
...
@@ -14,11 +16,12 @@ import org.apache.http.impl.nio.client.HttpAsyncClientBuilder
...
@@ -14,11 +16,12 @@ import org.apache.http.impl.nio.client.HttpAsyncClientBuilder
import
org.elasticsearch.client.RestClient
import
org.elasticsearch.client.RestClient
import
org.elasticsearch.client.RestClientBuilder.HttpClientConfigCallback
import
org.elasticsearch.client.RestClientBuilder.HttpClientConfigCallback
import
com.sksamuel.elastic4s.requests.searches.
{
SearchRequest
,
SearchResponse
}
import
com.sksamuel.elastic4s.requests.searches.sort.
{
FieldSort
,
SortOrder
,
ScriptSortType
}
import
com.sksamuel.elastic4s.ElasticDsl._
import
com.sksamuel.elastic4s.ElasticDsl._
import
com.sksamuel.elastic4s.
{
HitReader
,
Hit
,
ElasticClient
}
import
com.sksamuel.elastic4s.
{
HitReader
,
Hit
,
ElasticClient
,
Response
}
import
com.sksamuel.elastic4s.http.JavaClient
import
com.sksamuel.elastic4s.http.JavaClient
import
com.sksamuel.elastic4s.requests.searches.
{
SearchRequest
,
SearchResponse
}
import
com.sksamuel.elastic4s.requests.searches.sort.
{
FieldSort
,
SortOrder
,
ScriptSortType
}
import
com.sksamuel.elastic4s.requests.searches.queries.Query
import
com.sksamuel.elastic4s.requests.searches.queries.Query
import
com.sksamuel.elastic4s.requests.searches.queries.term.TermsQuery
import
com.sksamuel.elastic4s.requests.searches.queries.term.TermsQuery
import
com.sksamuel.elastic4s.requests.script.
{
Script
,
ScriptType
}
import
com.sksamuel.elastic4s.requests.script.
{
Script
,
ScriptType
}
...
@@ -51,13 +54,19 @@ object ESClient {
...
@@ -51,13 +54,19 @@ object ESClient {
}
}
object
ES
{
object
ES
{
case
class
Character
(
id
:
String
,
index
:
String
,
projects
:
String
)
implicit
object
ContentHitReader
extends
HitReader
[
Content
]
{
override
def
read
(
hit
:
Hit
)
:
Try
[
Content
]
=
{
implicit
object
CharacterHitReader
extends
HitReader
[
Character
]
{
override
def
read
(
hit
:
Hit
)
:
Try
[
Character
]
=
{
val
source
=
hit
.
sourceAsMap
val
source
=
hit
.
sourceAsMap
Try
(
Character
(
source
(
"id"
).
toString
,
hit
.
index
,
source
(
"tags_v3"
).
toString
))
Try
(
Content
(
source
(
"id"
).
toString
,
hit
.
index
,
source
(
"tags_v3"
).
toString
))
}
}
}
implicit
val
ec
:
scala.concurrent.ExecutionContext
=
scala
.
concurrent
.
ExecutionContext
.
global
def
request
(
req
:
SearchRequest
)
:
Future
[
IndexedSeq
[
Content
]]
=
{
val
client
:
ElasticClient
=
ESClient
.
create
(
"172.16.52.33"
,
9200
,
"elastic"
,
"gengmei!@#"
)
client
.
execute
(
req
).
map
(
resp
=>
resp
.
result
.
to
[
Content
])
// client.close()
}
}
def
test
(
def
test
(
...
@@ -83,7 +92,7 @@ object ES {
...
@@ -83,7 +92,7 @@ object ES {
// println(resp)
// println(resp)
val
a
=
resp
.
result
.
to
[
C
haracter
]
val
a
=
resp
.
result
.
to
[
C
ontent
]
println
(
"%%%%%%%%%%%"
)
println
(
"%%%%%%%%%%%"
)
println
(
a
.
size
)
println
(
a
.
size
)
...
...
src/main/scala/com.gmei.up/utils/Redis.scala
0 → 100644
View file @
db6097cd
package
com.gmei.up.utils
import
scala.concurrent.Future
import
com.redis.RedisClient
object
Redis
{
// TODO read from config file
implicit
val
ec
:
scala.concurrent.ExecutionContext
=
scala
.
concurrent
.
ExecutionContext
.
global
val
pRc4
=
new
RedisClient
(
"172.16.50.145"
,
6379
,
0
,
Some
(
"XfkMCCdWDIU%ls$h"
),
5000
)
def
save
(
content
:
Future
[
IndexedSeq
[
Content
]],
deviceId
:
String
,
contentType
:
String
)
:
Unit
=
{
val
key
=
s
"streaming:candidate:${contentType}:device_id:${deviceId}"
println
(
key
)
val
a
=
content
.
map
{
seq
=>
seq
.
map
{
c
=>
println
(
c
.
id
)
c
.
id
}
}
}
}
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