Friday, June 22, 2012

first qpid ruby example

Step 1: Add Exchange, Queue, and bind them.

[root@localhost qpidclient]# qpid-config -a guest/guest@localhost add exchange topic mytopic  --durable
[root@localhost qpidclient]# qpid-config -a guest/guest@localhost add queue myqueue
[root@localhost qpidclient]# qpid-config -a guest/guest@localhost bind mytopic myqueue

Using qpid-tool to check if add exchange and queue  successfully.


[root@localhost qpidclient]# qpid-tool
qpid: list exchange
Objects of type org.apache.qpid.broker:exchange
    ID   Created   Destroyed  Index
    ===============================================
    104  13:17:03  -          103.
    111  14:36:44  -          103.mytopic
 qpid: list queue
Objects of type org.apache.qpid.broker:queue
    ID   Created   Destroyed  Index
    ==============================================================
    117  14:38:50  -          103.myqueue


Step 2: Ruby Qpid producer code / server
[root@localhost qpidclient]# vim producer.rb
#!/usr/bin/env ruby

require "rubygems"
require "qpid"
require "socket"

conn = Qpid::Connection.new(TCPSocket.new("localhost", 5672),
                                         :username => "guest",
                                         :password => "guest")
conn.start(10)

ssn = conn.session("qpid_producer")

# create a queue
ssn.queue_declare("myqueue")
ssn.exchange_declare("mytopic", :type => "topic")

dp = ssn.delivery_properties(:routing_key => "myqueue")
mp = ssn.message_properties(:content_type => "text/plain")

ssn.message_transfer(:message => Qpid::Message.new(dp, mp, "hi5"))
while line = gets.strip
  break if line =~ /^(bye)$/i
  ssn.message_transfer(:message => Qpid::Message.new(dp, mp, line.strip))
end
ssn.message_transfer(:message => Qpid::Message.new(dp, mp, "exit"))
ssn.sync

ssn.close()
conn.close()




Step 3 QPID consumer code:


[root@localhost qpidclient]# vim consumer.rb
#!/usr/bin/env ruby

require "rubygems"
require "qpid"
require "socket"

conn = Qpid::Connection.new(TCPSocket.new("localhost", 5672),
                                         :username => "guest",
                                         :password => "guest")
conn.start(10)

ssn = conn.session("qpid_consumer")

incoming = ssn.incoming("messages")
ssn.message_subscribe(
  :destination => "messages",
  :queue => "myqueue",
  :accept_mode => ssn.message_accept_mode.none
)

# start incoming message flow
incoming.start()

while true
 body = incoming.get().body
 puts body
 break if body == "bye"
end

ssn.close()
conn.close()

Step 4: run producer and consumer
[root@localhost qpidclient]# ./producer.rb
hi
hello


[root@localhost qpidclient]# ./consumer.rb
hi
hello



Thursday, June 14, 2012

mysql change root password

mysql change root password

1, To setup root password for first time, use mysqladmin command at shell prompt as follows:
$ mysqladmin -u root password NEW_PASSWORD

2, update a root password,

$mysqladmin -u root -p'oldpassword' password newpass

For example,change old password 123 to 456
$ mysqladmin -u root -p123 password '456'

Monday, June 11, 2012

centos install git - use yum install

1,  Add the EPEL repository, then install it using yum.

  wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.i386.rpm
 
2, Install DAG's GPG key and Verify the package you have downloaded
    rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt
    rpm -K rpmforge-release-0.5.2-2.el5.rf.*.rpm

3, Install it
 rpm -i rpmforge-release-0.5.2-2.el5.rf.i386.rpm

4, install git using yum
  yum install git

Thursday, May 31, 2012

ESX VM - How to reset your password in Ubuntu

1, You need  hold down the Shift key during bootup.

2, From the boot menu, select recovery mode.

3, After you select recovery mode, then select "root shell prompt".

4, add user and passwd 

Tuesday, May 29, 2012

max width for image

<style type="text/css">
.my_img {
    max-width: 500px;
    /* Resize the image for IE6 */
    width: expression(this.width > 500 ? 500: true);
}
</style>

Thursday, May 24, 2012

squid add Password Authentication Using NCSA

1, generate /etc/squid/squid_passwd file

htpasswd -c /etc/squid/squid_passwd www


2, [root@localhost ~]# vim /etc/squid/squid.conf
a, Add this to the auth_param section of squid.conf
auth_param basic program /usr/lib/squid/ncsa_auth /etc/squid/squid_passwd

b, add this line in the buttom of acl
acl ncsa_users proxy_auth REQUIRED

c, add this line in the top of http_access
http_access allow ncsa_users