Class: Rex::Proto::Amqp::Version091::Client::Channel

Inherits:
Object
  • Object
show all
Includes:
Rex::Proto::Amqp::Version091
Defined in:
lib/rex/proto/amqp/version_0_9_1/client/channel.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, id) ⇒ Channel

Returns a new instance of Channel.



13
14
15
16
# File 'lib/rex/proto/amqp/version_0_9_1/client/channel.rb', line 13

def initialize(client, id)
  @client = client
  @id = id
end

Instance Attribute Details

#clientClient (readonly)

Returns The underlying AMQP client to which this channel belongs.

Returns:

  • (Client)

    The underlying AMQP client to which this channel belongs.



9
10
11
# File 'lib/rex/proto/amqp/version_0_9_1/client/channel.rb', line 9

def client
  @client
end

#idInteger (readonly)

Returns The channel ID.

Returns:

  • (Integer)

    The channel ID.



12
13
14
# File 'lib/rex/proto/amqp/version_0_9_1/client/channel.rb', line 12

def id
  @id
end

Instance Method Details

#basic_publish(exchange: '', routing_key: '', message: '', properties: {}) ⇒ NilClass

Publish a message on the channel.

Parameters:

  • exchange (String) (defaults to: '')

    The exchange to publish the message to.

  • routing_key (String) (defaults to: '')

    The routing key to publish the message with.

  • message (String) (defaults to: '')

    The message to publish.

  • properties (Hash) (defaults to: {})

    Properties to include in the content header when publishing.

Options Hash (properties:):

  • :content_type (String)
  • :content_encoding (String)
  • :headers (AmqpVersion091FieldTable)
  • :delivery_mode (Integer)
  • :priority (Integer)
  • :correlation_id (String)
  • :reply_to (String)
  • :expiration (String)
  • :message_id (String)
  • :timestamp (Time)
  • :message_type (String)
  • :user_id (String)
  • :app_id (String)
  • :cluster_id (String)

Returns:

  • (NilClass)


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/rex/proto/amqp/version_0_9_1/client/channel.rb', line 39

def basic_publish(exchange: '', routing_key: '', message: '', properties: {})
  ba_publish = Rex::Proto::Amqp::Version091::Frames::AmqpVersion091MethodFrame.new
  ba_publish.header.frame_channel = @id
  ba_publish.arguments = Rex::Proto::Amqp::Version091::Frames::MethodArguments::AmqpVersion091BasicPublish.new
  ba_publish.arguments.exchange = exchange
  ba_publish.arguments.routing_key = routing_key
  @client.send_frame(ba_publish)

  co_header = Rex::Proto::Amqp::Version091::Frames::AmqpVersion091ContentHeaderFrame.new
  co_header.header.frame_channel = @id
  co_header.body_size = message.size
  co_header.flags.snapshot.keys.each do |property|
    next unless properties[property]

    co_header.flags.send(property).assign(true)
    co_header.send(property).assign(properties[property])
  end
  @client.send_frame(co_header)

  co_body = Rex::Proto::Amqp::Version091::Frames::AmqpVersion091ContentBodyFrame.new
  co_body.header.frame_channel = @id
  co_body.payload = message
  @client.send_frame(co_body)

  nil
end

#closeObject



66
67
68
# File 'lib/rex/proto/amqp/version_0_9_1/client/channel.rb', line 66

def close
  @client.channel_close(self)
end