ios


Subscribe to exchange as separate function


I use singleton pattern for RabbitMQ:
final class ServiceBus{
static let Instance = ServiceBus()
var conn: RMQConnection;
var ch: RMQChannel;
var clientExchange: RMQExchange;
var clientQueue: RMQQueue;
private init() {
let delegate = RMQConnectionDelegateLogger()
self.conn = RMQConnection(uri: myUri, delegate: delegate)
self.conn.start()
self.ch = self.conn.createChannel()
self.clientExchange = ch.direct("Client")
self.clientQueue = ch.queue("", options: .exclusive)
}
}
I also have a lot of pages and I need subscribe to exchange via my sessionID. I subscribe again at every ViewController now:
class FirstViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
ServiceBus.Instance.clientQueue.bind(ServiceBus.Instance.clientExchange, routingKey: sessionID)
ServiceBus.Instance.clientQueue.subscribe({(_ message: RMQMessage) -> Void in
let message = String(data: message.body, encoding: .utf8)!
//...
})
}
}
class SecondViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
ServiceBus.Instance.clientQueue.bind(ServiceBus.Instance.clientExchange, routingKey: sessionID)
ServiceBus.Instance.clientQueue.subscribe({(_ message: RMQMessage) -> Void in
let message = String(data: message.body, encoding: .utf8)!
//...
})
}
}
How can I create a separate function to subscribe for exchange and use the same seperate function at different ViewControllers?

Related Links

iOS IPad Keyboard UIToolbar is unable to click for 1 seconds after done keying
UIImage next to centered UITextField Placeholder Text
Refresh token for ADAL authentication in iOS
Azure AD - Oauth2 returning Invalid Authentication Token
Issue in compiling project after updating to Xcode 8
How do I properly set my constraints for an adaptive layout?
What is the best way to add dynamic fields from JSON response
Pass data from View Controller to Class?
Read “structured/serialized data” from NSStream
Use Stripe Connect in Test Mode
read xmp metadata from jpeg in ios
iOS: starting Long-Running Tasks in foreground
Why can't I call a function in function update?
How to integrate authentication in Sirikit for apple watch using apple watchos3.2
Binary operator '==' cannot be applied to operands of type 'String?' and 'Bool' in Swift 3
viewDidAppear being called strangley

Categories

HOME
f#
whatsapp
coffeescript
apacheds
fonts
jsonschema
datetime
linear-programming
geany
pyusb
akka.net
autofac
calayer
signature
html5-video
smartsheet-c#-sdk-v2
lag
qualtrics
libssh
embed
atmelstudio
html-email
rational
many-to-many
aspdotnetstorefront
polynomials
iteration
angular-services
android-security
trial
parallax.js
kprobe
rdf4j
svn2git
jsplumb
kubernetes-go-client
gecko
photo-gallery
jdk1.6
gradient-descent
json-rpc
runge-kutta
google-slides
tern
backwards-compatibility
jquery-ui-dialog
sdcc
oracle-aq
spring-form
domdocument
formstack
jasmine2.0
complement
column-oriented
zbar
a-star
assembly-references
masspay
turbo-c
hard-drive-failure
mysql-notifier
measurement-protocol
turnjs
building
webpagetest
ng-annotate
vb6-migration
cover
skrollr
dbfit
clipping
sejda
xirr
wt
esky
tabbar
gevent-socketio
ehcache-bigmemory
generalization
modern-ui
tortoisecvs
imaging
datacontractserializer
short
jqgrid-php
confirmation
android-lru-cache
libavcodec
simpleaudioengine
gdb-python
hogan.js
haar-wavelet
oncreate
calloc
asp.net-session
onmouseout
letter-spacing
httpcontext.cache
treetop
nhaml

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App