Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
histhub
linker
Commits
b09daeb4
Commit
b09daeb4
authored
Jun 19, 2018
by
Tobias Steiner
Browse files
Managing backpressure
parent
f35bfe58
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/index.ts
View file @
b09daeb4
...
...
@@ -31,28 +31,36 @@ kafka.init().then(() => {
/**
* Get next from kafka
*/
consumer
.
consume
();
let
consuming
=
false
;
const
next
=
()
=>
{
consumer
.
consume
(
1
);
consuming
=
false
;
};
/**
* On data, write stuff to neo4j
*/
consumer
.
on
(
'
data
'
,
(
rawData
)
=>
{
co
re
.
getLogger
().
info
(
'
Consumed some data
'
)
;
co
nsuming
=
true
;
core
.
getReporter
().
setDataIn
(
1
);
// create new node
// rawData.parsed.provider = 'geonames';
// todo: we need to profile this error
// https://stackoverflow.com/questions/30403504/neo4j-merge-performance-vs-create-set
linker
.
connect
(
rawData
.
parsed
).
then
(()
=>
{
next
();
},
(
error
)
=>
{
core
.
getLogger
().
error
(
'
Could not save data to neo4j
'
+
JSON
.
stringify
(
error
));
consumer
.
disconnect
();
setTimeout
(()
=>
{
consumer
.
connect
();
consumer
.
consume
();
},
1000
);
next
();
});
});
setTimeout
(()
=>
{
if
(
consuming
===
false
)
{
next
();
}
},
100
);
});
},
(
err
)
=>
{
core
.
getLogger
().
error
(
'
Error while connecting to kafka
'
);
...
...
Write
Preview
Supports
Markdown
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