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

How to get the String Value in JSON
Add TapGestureRecogniser to UITextView
Navigation title not working properly
Chaning height of UIView
Getting same records from UITableView on Detail Button click in iOS
Interaction pop view controller from top to bottom swipe
Undeclared identifier error in UICollectionView
precompiler conditional compiling two cases
What does “Expression was too complex to be solved in reasonable time…” mean, and how can I fix it? [duplicate]
Update TableViewCell with Asynchronous data
Swift delegates - Newbie 3 ViewControllers
BLE - didDiscoverServices is never called
Making graphics for IOS applications
UITableView not reusing custom cell
Why setting labels.text from NSMutableArray does not work?
Swift2 error: 'UISearchController' is only available on iOS 8.0 or newer, despite deployment target 8.1

Categories

HOME
flutter
apache-spark
dynamic-programming
lsf
office-js
elf
serial-port
asana
twitter-digits
jqgrid
cross-compiling
development-environment
cytoscape.js
pouchdb
vulkan
reload
coreos
avr
spring-cloud-consul
jmespath
exe4j
collision
spark-graphx
sax
padding
esri
desire2learn
memorystream
coqide
clappr
reed-solomon
html-select
doctrine-odm
gridstack
delete-row
jdom-2
decompiler
extjs4
plasticscm
mamp-pro
free-diameter
msysgit
nscalendar
program-slicing
hydra
pci
autofocus
adsutil.vbs
rating-system
spring-form
html-lists
attributerouting
tastypie
qtcpserver
getelementbyid
singlepage
kie-workbench
android-sdk-tools
agile-processes
perspective
setwindowshookex
amazon-dynamodb-streams
cglib
singly-linked-list
python-3.1
cover
webmail
win32com
dual-table
ane
aldryn
cng
tun
symbian
gevent-socketio
puppet-enterprise
simpleadapter
slick2d
esx
epoll
sendto
spread-toolkit
asp.net-apicontroller
windward
populate
validform
resolver
micro-orm
couchpotato
cassette
ad-hoc-distribution
media-manager
force.com
ladon
openfeint
excel-web-query
drupal-gmap
contracts
development-machine
roguelike

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