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

Programming Transition Loses Navigation Bar
Go back to previous controller from class swift
Performance drop when switching between applications on iOS 9
Parse and Swift: How use advance targeting push to specific devices without users?
Dynamically adding multiline label in a view
How to bind with struct in ReactiveCocoa with Objective-C
iOS default keychain for unprivileged user used to start Tomcat and Jenkins
Changing background image for multiple platforms iOS
iOS How to update location of assets in photo editing extension?
How to link to Update page for our app
Object initialized with dictionary returns null
How to make UIProgressView work in swift
How to scroll the scrollview according to fields sizes in ios
How to implement didReceiveMemoryWarning in Swift?
Access Views inside custom UITableViewCell in iOS
UIScrollView, Autolayout and subviews

Categories

HOME
asp.net-mvc
html5-canvas
document
sqlite
clojure
lua
svg.js
delphi-xe7
pyusb
google-adwords
struts2-jquery
android-vision
google-weather-api
oracle-agile-plm
zap
windows-applications
cayley
pcap
dsc
scalability
json-c
apache-commons-httpclient
stomp
draggable
weebly
azure-management-api
jpype
subscription
multisite
itertools
tastypie
asp.net-mvc-custom-filter
agile-processes
evaluate
pygments
enhanced-ecommerce
hl7-v2
wgs84
aldryn
quasar
equinox
vraptor
lossless-compression
setattribute
imaging
httpservice
before-save
notifydatasetchanged
ituneslibrary
fay
confirmation
ioerror
buildout
pligg
nsusernotificationcenter
polarssl
rcu
source-highlighting
square-cube
clean-urls
browserid
time-limiting
force.com
cellid
noindex
molehill
server.mappath
mdi
blackberry-os-v5
nntp
treetop
android-3.1
rails-3.1
nsindexset
adbwireless
spquery
corporate-policy

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