Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
feudalBackend
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
16
Issues
16
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
feudal
feudalBackend
Commits
cdcb9386
Commit
cdcb9386
authored
Mar 12, 2018
by
Lukas Burgey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implemented reconnect after a closed rabbitmq connection
parent
1cebc43a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
11 deletions
+18
-11
django_backend/backend/models.py
django_backend/backend/models.py
+18
-11
No files found.
django_backend/backend/models.py
View file @
cdcb9386
...
...
@@ -2,8 +2,10 @@
# pylint: disable=unused-argument
import
json
import
time
import
logging
import
pika
from
pika.exceptions
import
ConnectionClosed
import
requests
from
requests.auth
import
HTTPBasicAuth
from
django.conf
import
settings
...
...
@@ -17,6 +19,7 @@ from rest_framework.authtoken.models import Token
from
.auth.v1.models
import
OIDCConfig
LOGGER
=
logging
.
getLogger
(
__name__
)
RECONNECT_TIMEOUT
=
3
# singleton for simple configs
...
...
@@ -99,7 +102,7 @@ class RabbitMQInstance(SingletonModel):
@
property
def
connection
(
self
):
LOGGER
.
debug
(
self
.
_msg
(
'
opened connection
'
))
LOGGER
.
debug
(
self
.
_msg
(
'
connection opened
'
))
return
pika
.
BlockingConnection
(
self
.
_connection_parameters
,
)
...
...
@@ -114,7 +117,7 @@ class RabbitMQInstance(SingletonModel):
exchange_type
=
'topic'
,
)
rabbitmq_channel
.
confirm_delivery
()
LOGGER
.
debug
(
self
.
_msg
(
'
opened channel
'
))
LOGGER
.
debug
(
self
.
_msg
(
'
channel opened
'
))
return
rabbitmq_channel
...
...
@@ -245,15 +248,19 @@ class RabbitMQInstance(SingletonModel):
if
self
.
is_client_connected
(
site
)]
def
publish_by_service
(
self
,
service
,
msg
):
# FIXME publish can fail -> catch error
return
self
.
channel
.
basic_publish
(
exchange
=
self
.
exchange
,
routing_key
=
service
.
routing_key
,
body
=
msg
,
properties
=
pika
.
BasicProperties
(
delivery_mode
=
1
,
),
)
while
True
:
try
:
return
self
.
channel
.
basic_publish
(
exchange
=
self
.
exchange
,
routing_key
=
service
.
routing_key
,
body
=
msg
,
properties
=
pika
.
BasicProperties
(
delivery_mode
=
1
,
),
)
except
ConnectionClosed
as
exception
:
LOGGER
.
info
(
self
.
_msg
(
'ConnectionClosed: {}'
.
format
(
exception
)))
time
.
sleep
(
RECONNECT_TIMEOUT
)
def
user_info_default
():
...
...
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