Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
I
ihooyah-flume
Overview
Overview
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
黄杰
ihooyah-flume
Commits
13c14bc9
Commit
13c14bc9
authored
May 14, 2021
by
吴凯波
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
flume监控ftp保存文件到服务器
parent
c3ad374e
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
10 deletions
+33
-10
pom.xml
pom.xml
+13
-1
LocalUploadSink.java
src/main/java/com/ihooyah/flume/sink/LocalUploadSink.java
+20
-9
No files found.
pom.xml
View file @
13c14bc9
...
...
@@ -18,7 +18,7 @@
<dependency>
<groupId>
org.apache.flume
</groupId>
<artifactId>
flume-ng-core
</artifactId>
<version>
${version.flume}
</version>
<version>
1.9.0
</version>
</dependency>
<dependency>
<groupId>
org.apache.flume
</groupId>
...
...
@@ -31,6 +31,17 @@
<artifactId>
mysql-connector-java
</artifactId>
<version>
6.0.5
</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
fastjson
</artifactId>
<version>
1.2.76
</version>
</dependency>
<dependency>
<groupId>
commons-net
</groupId>
<artifactId>
commons-net
</artifactId>
<version>
3.3
</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
src/main/java/com/ihooyah/flume/sink/LocalUploadSink.java
View file @
13c14bc9
...
...
@@ -10,10 +10,11 @@ import org.slf4j.LoggerFactory;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.FileWriter
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
public
class
LocalUploadSink
extends
AbstractSink
implements
Configurable
,
BatchSizeSupported
{
...
...
@@ -29,13 +30,15 @@ public class LocalUploadSink extends AbstractSink implements Configurable, Batch
private
String
fileReadName
;
private
CounterGroup
counterGroup
=
new
CounterGroup
();
@Override
public
Status
process
()
throws
EventDeliveryException
{
Map
<
String
,
List
<
Event
>>
eventMap
=
new
HashMap
<>();
Status
status
=
Status
.
READY
;
Channel
channel
=
getChannel
();
Transaction
transaction
=
channel
.
getTransaction
();
transaction
.
begin
();
List
<
Event
>
batch
=
new
ArrayList
<>();
try
{
for
(
int
i
=
0
;
i
<
batchSize
;
i
++)
{
Event
event
=
channel
.
take
();
...
...
@@ -43,13 +46,21 @@ public class LocalUploadSink extends AbstractSink implements Configurable, Batch
break
;
}
fileReadName
=
event
.
getHeaders
().
get
(
"fileName"
).
toString
();
System
.
out
.
println
(
"读取的文件名:"
+
fileReadName
);
batch
.
add
(
event
);
//System.out.println("读取文件名:"+fileReadName+" 文件大小:"+event.getBody().length);
this
.
counterGroup
.
incrementAndGet
(
"event.file"
);
List
<
Event
>
eventList
=
eventMap
.
get
(
fileReadName
);
if
(
eventList
==
null
){
eventList
=
new
ArrayList
<>();
}
eventList
.
add
(
event
);
eventMap
.
put
(
fileReadName
,
eventList
);
}
for
(
Map
.
Entry
<
String
,
List
<
Event
>>
data:
eventMap
.
entrySet
())
{
//System.out.println("文件名称:"+data.getKey()+"集合大小:"+data.getValue().size());
dealData
(
data
.
getKey
(),
data
.
getValue
());
}
dealData
(
batch
);
transaction
.
commit
();
}
catch
(
IO
Exception
e
)
{
}
catch
(
Exception
e
)
{
transaction
.
rollback
();
e
.
printStackTrace
();
}
finally
{
...
...
@@ -64,13 +75,13 @@ public class LocalUploadSink extends AbstractSink implements Configurable, Batch
batchSize
=
context
.
getInteger
(
"batchSize"
,
DEFAULT_BATCH_SIZE
);
}
public
void
dealData
(
List
<
Event
>
eventList
)
throws
IOException
{
public
void
dealData
(
String
fileName
,
List
<
Event
>
eventList
)
throws
IOException
{
if
(
eventList
.
size
()
==
0
)
{
return
;
}
logger
.
info
(
"deal data numbers: {}"
,
eventList
.
size
());
String
filename
=
System
.
currentTimeMillis
()
+
".png"
;
String
filename
=
System
.
currentTimeMillis
()
+
fileName
;
File
localFile
=
new
File
(
uploadDir
+
filename
);
FileOutputStream
fos
=
new
FileOutputStream
(
localFile
);
for
(
int
i
=
0
;
i
<
eventList
.
size
();
i
++)
{
...
...
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