public void publish(Task task) {
        try {
            ByteArrayOutputStream streamOutput = new ByteArrayOutputStream();
            ObjectOutput writer = new ObjectOutputStream(streamOutput);
            writer.writeObject(task);
            if (isPersistence())
                channel.basicPublish("", queueName, MessageProperties.PERSISTENT_TEXT_PLAIN, 
                        streamOutput.toByteArray());
            else 
                channel.basicPublish("", queueName, null, streamOutput.toByteArray());
            writer.close();
            streamOutput.close();
            try {
                Thread.sleep(1000);
            } catch (InterruptedException ex) {
                System.err.println(ex.getMessage());
            }
        } catch (IOException ex) {
            System.err.println(ex.getMessage());

        }
    }