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 recursively traverse NSDictionary in swift
How to prevent unwanted animations in UITableViewCell when animating UITableView
UIWebView to UIImage doesn't render full page
Drawing backgroundcolor & border Vs Background PNGs
Issue with Setting Orientation
Adding View, Removing it, and Adding it Again Breaks AutoLayout Constraints
How to use single APP_id for multiple Bundles ( Multiple apps) pushNotification
iOS 8 MDM: managed app configuration doesn't work
Twitter library error : Undefined symbols for architecture x86_64:
How can I preload an SKScene?
Sticking a TableView Header to the top, causes the header to not “interact” when user scrolls down
iOS App runs in simulator and devices ,But hangs in Xcode instruments- Memory allocations
What are these warnings in my console?
understanding ios stack trace [__NSArrayM insertObject:atIndex:]
Watchkit Interface Controller 38mm and 42mm background image size
Does XCode have something similar to properties files in Visual Studio

Categories

HOME
sbt
validation
ssl
wix
google-apis-explorer
coffeescript
sharepoint-2013
isis
asana
amazon-kinesis
prometheus
xquery
geany
jasypt
predictionio
silverlight
pymc3
proftpd
aac
command-line-interface
message
jgit
lazy-loading
orientdb-2.1
drupal-commerce
atg
powershell-v2.0
mouseevent
wso2cep
iteration
structure
simple-html-dom
text-parsing
whatsapi
jformattedtextfield
disqus
microsoft-translator
sagepay
nomenclature
worldpay
textangular
tabview
sweet.js
mediawiki-api
maven-jetty-plugin
adal.js
uifont
smartbanner
formstack
fido
laravel-routing
htc
ice
graph-traversal
android-alertdialog
pager
skrollr
linqtocsv
document-ready
nominatim
gulp-rename
netbsd
spatial-index
adserver
datacontractserializer
notifydatasetchanged
nine-patch
bson
blazeds
acts-as-taggable-on
buildout
broadcom
micro-orm
polarssl
firebird2.1
mysql-backup
network-scan
gumstix
dynamic-websites
versant-vod
user-testing

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