Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
swift-kafka
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Benedikt von St. Vieth
swift-kafka
Commits
1bbe78e6
Commit
1bbe78e6
authored
Dec 23, 2016
by
Benedikt von St. Vieth
Browse files
Options
Downloads
Patches
Plain Diff
swift-kafka now only writing to messagebus on response building.
parent
dd0fa63d
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
messagebus/messagebus.py
+18
-4
18 additions, 4 deletions
messagebus/messagebus.py
with
18 additions
and
4 deletions
messagebus/messagebus.py
+
18
−
4
View file @
1bbe78e6
...
@@ -5,6 +5,9 @@ from swift.common.utils import config_true_value, get_logger, split_path
...
@@ -5,6 +5,9 @@ from swift.common.utils import config_true_value, get_logger, split_path
from
swift.proxy.controllers.base
import
get_object_info
from
swift.proxy.controllers.base
import
get_object_info
from
webob
import
Request
,
Response
from
webob
import
Request
,
Response
from
kafka
import
KafkaProducer
import
json
class
MessagebusMiddleware
(
object
):
class
MessagebusMiddleware
(
object
):
"""
Middleware that sends information to message bus for every request.
"""
"""
Middleware that sends information to message bus for every request.
"""
...
@@ -25,7 +28,7 @@ class MessagebusMiddleware(object):
...
@@ -25,7 +28,7 @@ class MessagebusMiddleware(object):
log_route
=
'
messagebus
'
,
log_route
=
'
messagebus
'
,
log_to_console
=
False
)
log_to_console
=
False
)
def
__call__
(
self
,
env
,
start_response
):
def
__call__
(
self
,
req
,
start_response
):
"""
plug into the call.
"""
plug into the call.
:param env: request environment
:param env: request environment
...
@@ -33,9 +36,20 @@ class MessagebusMiddleware(object):
...
@@ -33,9 +36,20 @@ class MessagebusMiddleware(object):
:return:
:return:
"""
"""
self
.
start_response
=
start_response
self
.
start_response
=
start_response
#request = Request(env)
self
.
method
=
Request
(
req
).
method
self
.
logger
.
info
(
"
Messagebus Middleware
"
)
return
self
.
app
(
req
,
self
.
submit_to_messagebus
)
return
self
.
app
(
env
,
start_response
)
def
submit_to_messagebus
(
self
,
status
,
headers
,
exc_info
=
None
):
headers_send
=
dict
(
headers
)
# headers_send.pop('X-Auth-Token')
self
.
logger
.
info
(
headers_send
)
producer
=
KafkaProducer
(
bootstrap_servers
=
'
kafka
'
,
value_serializer
=
lambda
v
:
json
.
dumps
(
v
).
encode
(
'
utf-8
'
))
producer
.
send
(
'
swift-messagebus
'
,
headers_send
,
key
=
bytes
(
self
.
method
)
)
self
.
start_response
(
status
,
headers
)
def
filter_factory
(
global_config
,
**
local_conf
):
def
filter_factory
(
global_config
,
**
local_conf
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment