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

NSURLSession crash with JSON data parameter is nil while error is managed
PageViewController crashes on rotation
How to stop a dismissed view controller using a NSFetchedResultsController to listen to coredata changes?
UI getting blocked while fetching image path using Photos Framework in iOS
Read the value of a UILabel in Automation template of Instruments in Xcode
Prevent AdMob ad from reloading when changing view controllers
Animate moving of UICollectionViewCell
How to get images for only that data for which images are downloaded from the url
how to add title to side menu
Cordova push notification actions
How can I use a system sound as the sound for a UILocalNotification? [duplicate]
Cocos 2d build crash
I Wanted To Get Notified By Local Notification When My App Is In Background Or Else In Foreground
Refresh NSFetchedResultController in Swift
ios: Public Key SSL Pinning Returns Nil
Very large data for Xcode iOS unit tests

Categories

HOME
sbt
odoo-10
logstash
identityserver4
sharepoint-2013
azure-search
blogs
outlook
asana
passwords
chronicle
fpdf
gluon
android-bluetooth
entity
activerecord
apache-spark-sql
pie-chart
boxfuse
wavelet
graphengine
signature
spring-cloud-consul
amadeus
spring-boot-admin
orientdb-2.1
nsmutableattributedstring
snort
lexikjwtauthbundle
c-strings
robotium
precision
google-oauth2
x-sendfile
parallax.js
buffer-overflow
reformatting
rdf4j
bluebird
dlopen
petrel
edit-distance
fipy
extjs4
firedac
essbase
android-calendar
ssms-2012
asyncsocket
gcc4.8
fasta
jvm-arguments
graph-traversal
shift-reduce-conflict
rails-console
perspective
ubuntu-15.04
statistics-bootstrap
xendesktop
network-traffic
app-engine-ndb
webmail
facebook-comments
domo
dnx
jedi
dbfit
linq2db
ironmq
symbian
perfview
gem5
fastparse
slick2d
culture
office-2010
prettyfaces
jet.com-apis
httpservice
django-supervisor
keyboard-navigation
nine-patch
hobbitmon
jquery-backstretch
mydbr
youtrack-api
yourls
asciiencoding
ramdisk
dfsort
scala-pickling
sshj
nmea
couchrest
transport-stream
zephir
xcode4.2
nsmanagedobjectmodel
globbing
source-highlighting
osmf
shebang
google-provisioning-api
clean-urls
jsr223
mknetworkkit
b-method
servletunit
remote-control
iequalitycomparer
cracker
newsgroup
templatebinding
docking

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