Method: MessageBus::Implementation#publish
- Defined in:
- lib/message_bus.rb
#publish(channel, data, opts = nil) ⇒ Integer
Publishes a message to a channel
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 |
# File 'lib/message_bus.rb', line 334 def publish(channel, data, opts = nil) return if @off @mutex.synchronize do raise ::MessageBus::BusDestroyed if @destroyed end user_ids = nil group_ids = nil client_ids = nil site_id = nil if opts user_ids = opts[:user_ids] group_ids = opts[:group_ids] client_ids = opts[:client_ids] site_id = opts[:site_id] end if (user_ids || group_ids) && global?(channel) raise ::MessageBus::InvalidMessage end if (user_ids == []) || (group_ids == []) || (client_ids == []) raise ::MessageBus::InvalidMessageTarget end encoded_data = JSON.dump( data: data, user_ids: user_ids, group_ids: group_ids, client_ids: client_ids ) channel_opts = {} if opts if ((age = opts[:max_backlog_age]) || (size = opts[:max_backlog_size])) channel_opts[:max_backlog_size] = size channel_opts[:max_backlog_age] = age end if opts.has_key?(:queue_in_memory) channel_opts[:queue_in_memory] = opts[:queue_in_memory] end end encoded_channel_name = encode_channel_name(channel, site_id) reliable_pub_sub.publish(encoded_channel_name, encoded_data, channel_opts) end |