Method: MessageBus::Implementation#publish
- Defined in:
- lib/message_bus.rb
permalink #publish(channel, data, opts = nil) ⇒ Integer
Publishes a message to a channel
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 384 385 386 387 388 389 390 391 392 393 |
# File 'lib/message_bus.rb', line 344 def publish(channel, data, opts = nil) return if @off_disable_publish @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 = transport_codec.encode({ "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) backend_instance.publish(encoded_channel_name, encoded_data, channel_opts) end |